file_name
stringlengths
5
52
name
stringlengths
4
95
original_source_type
stringlengths
0
23k
source_type
stringlengths
9
23k
source_definition
stringlengths
9
57.9k
source
dict
source_range
dict
file_context
stringlengths
0
721k
dependencies
dict
opens_and_abbrevs
listlengths
2
94
vconfig
dict
interleaved
bool
1 class
verbose_type
stringlengths
1
7.42k
effect
stringclasses
118 values
effect_flags
sequencelengths
0
2
mutual_with
sequencelengths
0
11
ideal_premises
sequencelengths
0
236
proof_features
sequencelengths
0
1
is_simple_lemma
bool
2 classes
is_div
bool
2 classes
is_proof
bool
2 classes
is_simply_typed
bool
2 classes
is_type
bool
2 classes
partial_definition
stringlengths
5
3.99k
completed_definiton
stringlengths
1
1.63M
isa_cross_project_example
bool
1 class
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.ptr_loc
val ptr_loc (#a: _) (x: bpointer a) : Tot eloc
val ptr_loc (#a: _) (x: bpointer a) : Tot eloc
let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 58, "end_line": 113, "start_col": 0, "start_line": 113 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: EverParse3d.Actions.Base.bpointer a -> EverParse3d.Actions.Base.eloc
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.pointer", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "EverParse3d.Actions.Base.eloc" ]
[]
false
false
false
true
false
let ptr_loc #a (x: B.pointer a) : Tot eloc =
B.loc_buffer x
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_with_success_action
val validate_with_success_action (name: string) (#nz:bool) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#allow_reading:bool) (v1:validate_with_action_t p1 inv1 disj1 l1 allow_reading) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#b:bool) (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
val validate_with_success_action (name: string) (#nz:bool) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#allow_reading:bool) (v1:validate_with_action_t p1 inv1 disj1 l1 allow_reading) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#b:bool) (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 57, "end_line": 390, "start_col": 0, "start_line": 388 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 allow_reading -> a: EverParse3d.Actions.Base.action inv2 disj2 l2 b Prims.bool -> EverParse3d.Actions.Base.validate_with_action_t p1 (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.conj_disjointness disj1 disj2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.action", "EverParse3d.Actions.Base.validate_with_success_action'", "EverParse3d.Actions.Base.validate_drop", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.eloc_union" ]
[]
false
false
false
false
false
let validate_with_success_action name v1 a =
validate_with_success_action' name (validate_drop v1) a
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.index_equations
val index_equations (_:unit) : Lemma (ensures ( //true_inv left unit (forall (d:slice_inv). {:pattern (true_inv `conj_inv` d)} (true_inv `conj_inv` d) == d) /\ //true_inv right unit (forall (d:slice_inv). {:pattern (d `conj_inv` true_inv)} (d `conj_inv` true_inv) == d) /\ //eloc_none left unit (forall (l:eloc). {:pattern (l `eloc_union` eloc_none)} (l `eloc_union` eloc_none) == l) /\ //eloc_none right unit (forall (l:eloc). {:pattern (eloc_none `eloc_union` l)} (eloc_none `eloc_union` l) == l) /\ //disjoint eloc_none right trivial (forall (l:eloc). {:pattern (disjoint l eloc_none)} (disjoint l eloc_none) == disjointness_trivial) /\ //disjoint eloc_none left trivial (forall (l:eloc). {:pattern (disjoint eloc_none l)} (disjoint eloc_none l) == disjointness_trivial) /\ //disjointness_pre right unit (forall (d:disjointness_pre). {:pattern (conj_disjointness d disjointness_trivial)} (conj_disjointness d disjointness_trivial) == d) /\ //disjointness_pre left unit (forall (d:disjointness_pre). {:pattern (conj_disjointness disjointness_trivial d)} (conj_disjointness disjointness_trivial d) == d) /\ //imp_disjointness refl (forall (d:disjointness_pre). {:pattern (imp_disjointness d d)} imp_disjointness d d) /\ //inv_implies refl (forall (i:slice_inv). {:pattern (inv_implies i i)} inv_implies i i) /\ //inv_implies true_inv right trivial (forall (i:slice_inv). {:pattern (inv_implies i true_inv)} inv_implies i true_inv) /\ //inv_implies_conj (forall (i0 i1 i2:slice_inv). {:pattern (i0 `inv_implies` (i1 `conj_inv` i2))} (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2))) /\ //eloc_includes_none (forall (l:eloc). {:pattern (l `eloc_includes` eloc_none)} l `eloc_includes` eloc_none) /\ //eloc_includes_union (forall (l0 l1 l2:eloc). {:pattern (l0 `eloc_includes` (l1 `eloc_union` l2))} (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2))) /\ //eloc_includes_refl (forall (l:eloc). {:pattern (l `eloc_includes` l)} (l `eloc_includes` l)) ))
val index_equations (_:unit) : Lemma (ensures ( //true_inv left unit (forall (d:slice_inv). {:pattern (true_inv `conj_inv` d)} (true_inv `conj_inv` d) == d) /\ //true_inv right unit (forall (d:slice_inv). {:pattern (d `conj_inv` true_inv)} (d `conj_inv` true_inv) == d) /\ //eloc_none left unit (forall (l:eloc). {:pattern (l `eloc_union` eloc_none)} (l `eloc_union` eloc_none) == l) /\ //eloc_none right unit (forall (l:eloc). {:pattern (eloc_none `eloc_union` l)} (eloc_none `eloc_union` l) == l) /\ //disjoint eloc_none right trivial (forall (l:eloc). {:pattern (disjoint l eloc_none)} (disjoint l eloc_none) == disjointness_trivial) /\ //disjoint eloc_none left trivial (forall (l:eloc). {:pattern (disjoint eloc_none l)} (disjoint eloc_none l) == disjointness_trivial) /\ //disjointness_pre right unit (forall (d:disjointness_pre). {:pattern (conj_disjointness d disjointness_trivial)} (conj_disjointness d disjointness_trivial) == d) /\ //disjointness_pre left unit (forall (d:disjointness_pre). {:pattern (conj_disjointness disjointness_trivial d)} (conj_disjointness disjointness_trivial d) == d) /\ //imp_disjointness refl (forall (d:disjointness_pre). {:pattern (imp_disjointness d d)} imp_disjointness d d) /\ //inv_implies refl (forall (i:slice_inv). {:pattern (inv_implies i i)} inv_implies i i) /\ //inv_implies true_inv right trivial (forall (i:slice_inv). {:pattern (inv_implies i true_inv)} inv_implies i true_inv) /\ //inv_implies_conj (forall (i0 i1 i2:slice_inv). {:pattern (i0 `inv_implies` (i1 `conj_inv` i2))} (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2))) /\ //eloc_includes_none (forall (l:eloc). {:pattern (l `eloc_includes` eloc_none)} l `eloc_includes` eloc_none) /\ //eloc_includes_union (forall (l0 l1 l2:eloc). {:pattern (l0 `eloc_includes` (l1 `eloc_union` l2))} (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2))) /\ //eloc_includes_refl (forall (l:eloc). {:pattern (l `eloc_includes` l)} (l `eloc_includes` l)) ))
let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 29, "end_line": 110, "start_col": 0, "start_line": 73 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Pervasives.Lemma (ensures (forall (d: EverParse3d.Actions.Base.slice_inv). {:pattern EverParse3d.Actions.Base.conj_inv EverParse3d.Actions.Base.true_inv d} EverParse3d.Actions.Base.conj_inv EverParse3d.Actions.Base.true_inv d == d) /\ (forall (d: EverParse3d.Actions.Base.slice_inv). {:pattern EverParse3d.Actions.Base.conj_inv d EverParse3d.Actions.Base.true_inv} EverParse3d.Actions.Base.conj_inv d EverParse3d.Actions.Base.true_inv == d) /\ (forall (l: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.eloc_union l EverParse3d.Actions.Base.eloc_none} EverParse3d.Actions.Base.eloc_union l EverParse3d.Actions.Base.eloc_none == l) /\ (forall (l: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.eloc_union EverParse3d.Actions.Base.eloc_none l} EverParse3d.Actions.Base.eloc_union EverParse3d.Actions.Base.eloc_none l == l) /\ (forall (l: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.disjoint l EverParse3d.Actions.Base.eloc_none} EverParse3d.Actions.Base.disjoint l EverParse3d.Actions.Base.eloc_none == EverParse3d.Actions.Base.disjointness_trivial) /\ (forall (l: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.disjoint EverParse3d.Actions.Base.eloc_none l} EverParse3d.Actions.Base.disjoint EverParse3d.Actions.Base.eloc_none l == EverParse3d.Actions.Base.disjointness_trivial) /\ (forall (d: EverParse3d.Actions.Base.disjointness_pre). {:pattern EverParse3d.Actions.Base.conj_disjointness d EverParse3d.Actions.Base.disjointness_trivial} EverParse3d.Actions.Base.conj_disjointness d EverParse3d.Actions.Base.disjointness_trivial == d) /\ (forall (d: EverParse3d.Actions.Base.disjointness_pre). {:pattern EverParse3d.Actions.Base.conj_disjointness EverParse3d.Actions.Base.disjointness_trivial d} EverParse3d.Actions.Base.conj_disjointness EverParse3d.Actions.Base.disjointness_trivial d == d) /\ (forall (d: EverParse3d.Actions.Base.disjointness_pre). {:pattern EverParse3d.Actions.Base.imp_disjointness d d} EverParse3d.Actions.Base.imp_disjointness d d) /\ (forall (i: EverParse3d.Actions.Base.slice_inv). {:pattern EverParse3d.Actions.Base.inv_implies i i} EverParse3d.Actions.Base.inv_implies i i) /\ (forall (i: EverParse3d.Actions.Base.slice_inv). {:pattern EverParse3d.Actions.Base.inv_implies i EverParse3d.Actions.Base.true_inv} EverParse3d.Actions.Base.inv_implies i EverParse3d.Actions.Base.true_inv) /\ (forall (i0: EverParse3d.Actions.Base.slice_inv) (i1: EverParse3d.Actions.Base.slice_inv) (i2: EverParse3d.Actions.Base.slice_inv). {:pattern EverParse3d.Actions.Base.inv_implies i0 (EverParse3d.Actions.Base.conj_inv i1 i2)} EverParse3d.Actions.Base.inv_implies i0 i1 /\ EverParse3d.Actions.Base.inv_implies i0 i2 ==> EverParse3d.Actions.Base.inv_implies i0 (EverParse3d.Actions.Base.conj_inv i1 i2)) /\ (forall (l: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.eloc_includes l EverParse3d.Actions.Base.eloc_none} EverParse3d.Actions.Base.eloc_includes l EverParse3d.Actions.Base.eloc_none) /\ (forall (l0: EverParse3d.Actions.Base.eloc) (l1: EverParse3d.Actions.Base.eloc) (l2: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.eloc_includes l0 (EverParse3d.Actions.Base.eloc_union l1 l2)} EverParse3d.Actions.Base.eloc_includes l0 l1 /\ EverParse3d.Actions.Base.eloc_includes l0 l2 ==> EverParse3d.Actions.Base.eloc_includes l0 (EverParse3d.Actions.Base.eloc_union l1 l2)) /\ (forall (l: EverParse3d.Actions.Base.eloc). {:pattern EverParse3d.Actions.Base.eloc_includes l l} EverParse3d.Actions.Base.eloc_includes l l))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Prims.unit", "FStar.Classical.Sugar.forall_intro", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.eloc_includes", "EverParse3d.Actions.Base.eloc_includes_refl", "Prims.squash", "Prims.l_Forall", "Prims.l_imp", "Prims.l_and", "EverParse3d.Actions.Base.eloc_union", "FStar.Classical.Sugar.implies_intro", "EverParse3d.Actions.Base.eloc_includes_union", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.eloc_includes_none", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.inv_implies", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.inv_implies_conj", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.inv_implies_true", "EverParse3d.Actions.Base.inv_implies_refl", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.imp_disjointness", "EverParse3d.Actions.Base.imp_disjointness_refl", "Prims.eq2", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.conj_disjointness_trivial_right_unit", "EverParse3d.Actions.Base.conj_disjointness_trivial_left_unit", "EverParse3d.Actions.Base.disjoint", "EverParse3d.Actions.Base.disjoint_none_l", "EverParse3d.Actions.Base.disjoint_none_r", "EverParse3d.Actions.Base.eloc_union_none_left_unit", "EverParse3d.Actions.Base.eloc_union_none_right_unit", "EverParse3d.Actions.Base.conj_inv_true_right_unit", "EverParse3d.Actions.Base.conj_inv_true_left_unit" ]
[]
false
false
true
false
false
let index_equations () =
introduce forall d . _ with conj_inv_true_left_unit d; introduce forall d . _ with conj_inv_true_right_unit d; introduce forall l . _ with eloc_union_none_right_unit l; introduce forall l . _ with eloc_union_none_left_unit l; introduce forall l . _ with disjoint_none_r l; introduce forall l . _ with disjoint_none_l l; introduce forall d . _ with conj_disjointness_trivial_left_unit d; introduce forall d . _ with conj_disjointness_trivial_right_unit d; introduce forall d . _ with imp_disjointness_refl d; introduce forall i . _ with inv_implies_refl i; introduce forall i . _ with inv_implies_true i; introduce forall i0 i1 i2 . (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _. inv_implies_conj i0 i1 i2 () (); introduce forall l . _ with eloc_includes_none l; introduce forall l0 l1 l2 . (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _. eloc_includes_union l0 l1 l2 () (); introduce forall l . _ with eloc_includes_refl l
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.app_loc
val app_loc (x: AppCtxt.app_ctxt) (l: eloc) : eloc
val app_loc (x: AppCtxt.app_ctxt) (l: eloc) : eloc
let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 32, "end_line": 118, "start_col": 0, "start_line": 116 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: EverParse3d.AppCtxt.app_ctxt -> l: EverParse3d.Actions.Base.eloc -> EverParse3d.Actions.Base.eloc
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.AppCtxt.app_ctxt", "EverParse3d.Actions.Base.eloc", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.AppCtxt.loc_of", "FStar.Ghost.reveal", "Prims.unit", "EverParse3d.AppCtxt.properties" ]
[]
false
false
false
true
false
let app_loc (x: AppCtxt.app_ctxt) (l: eloc) : eloc =
AppCtxt.properties x; (AppCtxt.loc_of x) `loc_union` l
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.valid_length
val valid_length (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop
val valid_length (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop
let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 218, "start_col": 0, "start_line": 201 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> h: FStar.Monotonic.HyperStack.mem -> sl: input_buffer_t -> len: Prims.int -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.input_stream_inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.Monotonic.HyperStack.mem", "Prims.int", "Prims.l_and", "EverParse3d.InputStream.Base.live", "LowParse.Spec.Base.parse", "Prims.l_False", "LowParse.Spec.Base.consumed_length", "Prims.eq2", "Prims.logical", "FStar.Seq.Base.seq", "FStar.UInt8.t", "EverParse3d.InputStream.Base.get_remaining", "Prims.prop" ]
[]
false
false
false
false
true
let valid_length (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop =
I.live sl h /\ (let s = I.get_remaining sl h in match LP.parse p s with | None -> False | Some (_, len') -> len == len')
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action
val action (liveness_inv:slice_inv) (disj:disjointness_pre) (modifies_l:eloc) (on_success:bool) (a:Type) : Type0
val action (liveness_inv:slice_inv) (disj:disjointness_pre) (modifies_l:eloc) (on_success:bool) (a:Type) : Type0
let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 15, "end_line": 174, "start_col": 0, "start_line": 149 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
liveness_inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> modifies_l: EverParse3d.Actions.Base.eloc -> on_success: Prims.bool -> a: Type -> Type0
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Base.footprint", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt64.v", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.Seq.Base.length", "EverParse3d.InputStream.Base.get_read", "LowStar.Monotonic.Buffer.modifies", "FStar.Ghost.hide" ]
[]
false
false
false
true
true
let action inv disj l on_success a =
#[EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t -> ctxt: app_ctxt -> error_handler_fn: error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ (loc_not_unused_in h) `loc_includes` (app_loc ctxt l) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt l) /\ (app_loc ctxt l) `loc_disjoint` (I.footprint sl) /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h)) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.error_handler
val error_handler : Type0
let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 20, "end_line": 147, "start_col": 0, "start_line": 125 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "FStar.UInt64.t", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.ErrorCode.pos_t", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.true_inv", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "EverParse3d.Actions.Base.eloc_none", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Base.footprint", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt64.v", "FStar.Seq.Base.length", "EverParse3d.InputStream.Base.get_read", "LowStar.Monotonic.Buffer.modifies", "FStar.Ghost.hide" ]
[]
false
false
false
true
true
let error_handler =
typename: string -> fieldname: string -> error_reason: string -> error_code: U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ (loc_not_unused_in h) `loc_includes` (app_loc ctxt eloc_none) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt eloc_none) /\ (app_loc ctxt eloc_none) `loc_disjoint` (I.footprint sl) /\ U64.v pos <= Seq.length (I.get_read sl h)) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.valid
val valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop
val valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop
let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h))
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 43, "end_line": 230, "start_col": 0, "start_line": 220 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> h: FStar.Monotonic.HyperStack.mem -> sl: input_buffer_t -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.input_stream_inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Base.parse", "Prims.prop" ]
[]
false
false
false
false
true
let valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop =
I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.valid_consumed
val valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop
val valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop
let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 198, "start_col": 0, "start_line": 180 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> sl: input_buffer_t -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.input_stream_inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "LowParse.Spec.Base.parse", "Prims.l_False", "LowParse.Spec.Base.consumed_length", "FStar.Seq.Base.equal", "FStar.UInt8.t", "EverParse3d.InputStream.Base.get_remaining", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.logical", "FStar.Seq.Base.seq", "Prims.prop" ]
[]
false
false
false
false
true
let valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop =
I.live sl h /\ I.live sl h' /\ (let s = I.get_remaining sl h in match LP.parse p s with | None -> False | Some (_, len) -> (I.get_remaining sl h') `Seq.equal` (Seq.slice s len (Seq.length s)))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.leaf_reader
val leaf_reader (#nz:bool) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (p: parser k t) : Type u#0
val leaf_reader (#nz:bool) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (p: parser k t) : Type u#0
let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end ))
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 4, "end_line": 317, "start_col": 0, "start_line": 292 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: EverParse3d.Prelude.parser k t -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.Actions.Base.valid", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.Seq.Base.length", "FStar.UInt8.t", "EverParse3d.InputStream.Base.get_read", "EverParse3d.InputStream.Base.live", "LowStar.Monotonic.Buffer.modifies", "EverParse3d.InputStream.Base.perm_footprint", "LowParse.Spec.Base.parse", "Prims.l_False", "LowParse.Spec.Base.consumed_length", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "FStar.Seq.Base.slice", "Prims.logical" ]
[]
false
false
false
false
true
let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type =
(#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h))) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ (match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) )))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_drop
val validate_drop (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#disj: disjointness_pre) (#l: eloc) (#allow_reading: _) (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false)
val validate_drop (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#disj: disjointness_pre) (#l: eloc) (#allow_reading: _) (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false)
let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 8, "end_line": 386, "start_col": 0, "start_line": 374 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t' p inv disj l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t' p inv disj l false
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t'", "EverParse3d.Actions.Base.validate_drop_true" ]
[]
false
false
false
false
false
let validate_drop (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#disj: disjointness_pre) (#l: eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) =
if allow_reading then validate_drop_true v else v
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_chan_inv
val intro_chan_inv (#p: _) (c: chan_t p) (v: chan_val) : SteelT unit (((pts_to c.send half v) `star` (pts_to c.recv half v)) `star` (trace_until c.trace v)) (fun _ -> chan_inv c)
val intro_chan_inv (#p: _) (c: chan_t p) (v: chan_val) : SteelT unit (((pts_to c.send half v) `star` (pts_to c.recv half v)) `star` (trace_until c.trace v)) (fun _ -> chan_inv c)
let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 28, "end_line": 157, "start_col": 0, "start_line": 152 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Steel.Channel.Simplex.chan_t p -> v: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.intro_chan_inv_eqT", "Prims.unit", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let intro_chan_inv #p (c: chan_t p) (v: chan_val) : SteelT unit (((pts_to c.send half v) `star` (pts_to c.recv half v)) `star` (trace_until c.trace v)) (fun _ -> chan_inv c) =
intro_chan_inv_eqT c v v
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.act_with_comment
val act_with_comment (s: string) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#b:_) (res:Type) (a: action inv disj l b res) : Tot (action inv disj l b res)
val act_with_comment (s: string) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#b:_) (res:Type) (a: action inv disj l b res) : Tot (action inv disj l b res)
let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 28, "end_line": 290, "start_col": 0, "start_line": 285 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
s: Prims.string -> res: Type -> a: EverParse3d.Actions.Base.action inv disj l b res -> EverParse3d.Actions.Base.action inv disj l b res
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.action", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "Prims.unit", "LowParse.Low.Base.comment" ]
[]
false
false
false
false
false
let act_with_comment s res a =
fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_dep_pair_with_refinement_and_action
val validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#[@@@erasable] inv1':slice_inv) (#[@@@erasable] disj1':disjointness_pre) (#[@@@erasable] l1':eloc) (#b:_) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false
val validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#[@@@erasable] inv1':slice_inv) (#[@@@erasable] disj1':disjointness_pre) (#[@@@erasable] l1':eloc) (#b:_) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false
let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 70, "end_line": 602, "start_col": 0, "start_line": 585 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p1_is_constant_size_without_actions: Prims.bool -> name1: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 true -> r1: EverParse3d.Actions.Base.leaf_reader p1 -> f: (_: t1 -> Prims.bool) -> a: (_: t1 -> EverParse3d.Actions.Base.action inv1' disj1' l1' b Prims.bool) -> v2: (x: EverParse3d.Prelude.refine t1 f -> EverParse3d.Actions.Base.validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (EverParse3d.Prelude.parse_filter p1 f) p2) (EverParse3d.Actions.Base.conj_inv inv1 (EverParse3d.Actions.Base.conj_inv inv1' inv2)) (EverParse3d.Actions.Base.conj_disjointness disj1 (EverParse3d.Actions.Base.conj_disjointness disj1' disj2)) (EverParse3d.Actions.Base.eloc_union l1 (EverParse3d.Actions.Base.eloc_union l1' l2)) false
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.string", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.action", "EverParse3d.Kinds.weak_kind", "EverParse3d.Prelude.refine", "LowParse.Spec.Base.bool_and", "Prims.op_Equality", "FStar.Pervasives.Native.option", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "EverParse3d.Actions.Base.validate_dep_pair_with_refinement_and_action_total_zero_parser'", "EverParse3d.Actions.Base.validate_dep_pair_with_refinement_and_action'", "Prims.op_BarBar", "EverParse3d.Kinds.and_then_kind", "EverParse3d.Kinds.filter_kind", "Prims.dtuple2", "EverParse3d.Prelude.parse_dep_pair", "EverParse3d.Prelude.parse_filter", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.eloc_union" ]
[]
false
false
false
false
false
let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1: parser_kind nz1 _) #t1 (#p1: parser k1 t1) #inv1 #disj1 #l1 (v1: validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: (t1 -> bool)) #inv1' #disj1' #l1' #b (a: (t1 -> action inv1' disj1' l1' b bool)) #nz2 #wk2 (#k2: parser_kind nz2 wk2) (#t2: (refine _ f -> Type)) (#p2: (x: refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2: (x: refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) =
if (p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0)) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_ret
val validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true
val validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true
let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 18, "end_line": 424, "start_col": 0, "start_line": 421 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_ret ()) EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none true
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.ret_kind", "Prims.unit", "EverParse3d.Prelude.parse_ret", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none" ]
[]
false
false
false
false
false
let validate_ret:validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true =
fun ctxt error_handler_fn input input_length start_position -> start_position
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.recall_trace_ref
val recall_trace_ref (#q: _) (r: trace_ref q) (tr tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr')
val recall_trace_ref (#q: _) (r: trace_ref q) (tr tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr')
let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 40, "end_line": 427, "start_col": 0, "start_line": 420 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t)
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.Channel.Simplex.trace_ref q -> tr: Steel.Channel.Protocol.partial_trace_of q -> tr': Steel.Channel.Protocol.partial_trace_of q -> tok: Steel.MonotonicHigherReference.witnessed r (Steel.Channel.Simplex.history_p tr) -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.trace_ref", "Steel.Channel.Protocol.partial_trace_of", "Steel.MonotonicHigherReference.witnessed", "Steel.Channel.Protocol.extended_to", "Steel.Channel.Simplex.history_p", "Steel.MonotonicHigherReference.recall", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.FractionalPermission.full_perm", "Steel.MonotonicHigherReference.ref", "Prims.unit", "Steel.MonotonicHigherReference.pts_to", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
false
true
false
false
false
let recall_trace_ref #q (r: trace_ref q) (tr: partial_trace_of q) (tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') =
MRef.recall (history_p tr) r tr' tok
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_weaken_right
val validate_weaken_right (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (#nz':_) (#wk': _) (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv disj l allow_reading
val validate_weaken_right (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (#nz':_) (#wk': _) (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv disj l allow_reading
let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k')
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 30, "end_line": 865, "start_col": 0, "start_line": 861 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> k': EverParse3d.Kinds.parser_kind nz' wk' -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_weaken_right p k') inv disj l allow_reading
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.validate_weaken", "Prims.op_AmpAmp", "EverParse3d.Kinds.weak_kind_glb", "EverParse3d.Kinds.glb", "EverParse3d.Prelude.parse_weaken_right" ]
[]
false
false
false
false
false
let validate_weaken_right #nz #wk (#k: parser_kind nz wk) (#t: _) (#p: parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) #nz' #wk' (k': parser_kind nz' wk') =
validate_weaken v (glb k k')
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_dep_pair_with_refinement
val validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
val validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 55, "end_line": 750, "start_col": 0, "start_line": 732 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p1_is_constant_size_without_actions: Prims.bool -> name1: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 true -> r1: EverParse3d.Actions.Base.leaf_reader p1 -> f: (_: t1 -> Prims.bool) -> v2: (x: EverParse3d.Prelude.refine t1 f -> EverParse3d.Actions.Base.validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (EverParse3d.Prelude.parse_filter p1 f) p2) (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.conj_disjointness disj1 disj2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.string", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.weak_kind", "EverParse3d.Prelude.refine", "LowParse.Spec.Base.bool_and", "Prims.op_Equality", "FStar.Pervasives.Native.option", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "EverParse3d.Actions.Base.validate_dep_pair_with_refinement_total_zero_parser'", "EverParse3d.Actions.Base.validate_dep_pair_with_refinement'", "Prims.op_BarBar", "EverParse3d.Kinds.and_then_kind", "EverParse3d.Kinds.filter_kind", "Prims.dtuple2", "EverParse3d.Prelude.parse_dep_pair", "EverParse3d.Prelude.parse_filter", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.eloc_union" ]
[]
false
false
false
false
false
let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1: parser_kind nz1 _) #t1 (#p1: parser k1 t1) #inv1 #disj1 #l1 (v1: validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: (t1 -> bool)) #nz2 #wk2 (#k2: parser_kind nz2 wk2) (#t2: (refine _ f -> Type)) (#p2: (x: refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2: (x: refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) =
if (p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0)) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_weaken_left
val validate_weaken_left (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (#nz':_) (#wk': _) (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv disj l allow_reading
val validate_weaken_left (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (#nz':_) (#wk': _) (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv disj l allow_reading
let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 30, "end_line": 856, "start_col": 0, "start_line": 852 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> k': EverParse3d.Kinds.parser_kind nz' wk' -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_weaken_left p k') inv disj l allow_reading
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.validate_weaken", "Prims.op_AmpAmp", "EverParse3d.Kinds.weak_kind_glb", "EverParse3d.Kinds.glb", "EverParse3d.Prelude.parse_weaken_left" ]
[]
false
false
false
false
false
let validate_weaken_left #nz #wk (#k: parser_kind nz wk) (#t: _) (#p: parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) #nz' #wk' (k': parser_kind nz' wk') =
validate_weaken v (glb k' k)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_total_constant_size_no_read
val validate_total_constant_size_no_read (#nz #wk: _) (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv disj l: _) : Tot (validate_with_action_t p inv disj l true)
val validate_total_constant_size_no_read (#nz #wk: _) (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv disj l: _) : Tot (validate_with_action_t p inv disj l true)
let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 57, "end_line": 1187, "start_col": 0, "start_line": 1174 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: EverParse3d.Prelude.parser k t -> sz: FStar.UInt64.t -> u1493: u1497: Prims.unit { Mkparser_kind'?.parser_kind_high k == FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\ Mkparser_kind'?.parser_kind_low k == FStar.UInt64.v sz /\ Mkparser_kind'?.parser_kind_metadata k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserKindMetadataTotal } -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> EverParse3d.Actions.Base.validate_with_action_t p inv disj l true
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "FStar.UInt64.t", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_total_constant_size_no_read'", "EverParse3d.Actions.Base.validate_with_action_t" ]
[]
false
false
false
false
false
let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) =
validate_total_constant_size_no_read' p sz u inv disj l
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list_inv
val validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0
val validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0
let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 92, "end_line": 931, "start_col": 0, "start_line": 882 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> g0: FStar.Ghost.erased FStar.Monotonic.HyperStack.mem -> g1: FStar.Ghost.erased FStar.Monotonic.HyperStack.mem -> ctxt: EverParse3d.Actions.Base.app_ctxt -> sl: EverParse3d.Actions.Base.input_buffer_t -> bres: LowStar.Buffer.pointer FStar.UInt64.t -> h: FStar.Monotonic.HyperStack.mem -> stop: Prims.bool -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "FStar.Ghost.erased", "FStar.Monotonic.HyperStack.mem", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.input_buffer_t", "LowStar.Buffer.pointer", "FStar.UInt64.t", "Prims.bool", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Base.footprint", "EverParse3d.InputStream.All.inst", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "EverParse3d.InputStream.Base.live", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "EverParse3d.ErrorCode.is_error", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt64.v", "EverParse3d.ErrorCode.get_validator_error_pos", "EverParse3d.InputStream.Base.get_read", "Prims.l_imp", "Prims.op_disEquality", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "Prims.l_not", "EverParse3d.Actions.Base.valid", "LowParse.Spec.List.parse_list_kind", "Prims.list", "LowParse.Spec.List.parse_list", "Prims.l_iff", "Prims.logical", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.InputStream.Base.perm_footprint", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq" ]
[]
false
false
false
false
true
let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 =
let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ (loc_not_unused_in h0) `loc_includes` (app_loc ctxt l) /\ (app_loc ctxt l) `loc_disjoint` (I.footprint sl) /\ (app_loc ctxt l) `loc_disjoint` (loc_buffer bres) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt l) /\ (B.loc_buffer bres) `B.loc_disjoint` (I.footprint sl) /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ (let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` (Seq.slice s (Seq.length s - Seq.length s') (Seq.length s))) /\ modifies loc_none h0 h1 /\ (if LPE.is_error res then stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~(valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0))) /\ modifies (((app_loc ctxt l) `loc_union` (loc_buffer bres)) `loc_union` (I.perm_footprint sl)) h1 h
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_with_error_handler
val validate_with_error_handler (typename: string) (fieldname: string) (#nz: _) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1: Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj l1 ar) : validate_with_action_t p1 inv1 disj l1 ar
val validate_with_error_handler (typename: string) (fieldname: string) (#nz: _) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1: Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj l1 ar) : validate_with_action_t p1 inv1 disj l1 ar
let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 )
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 418, "start_col": 0, "start_line": 393 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
typename: Prims.string -> fieldname: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj l1 ar -> EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj l1 ar
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_success", "FStar.UInt64.t", "Prims.unit", "EverParse3d.ErrorCode.error_reason_of_result", "EverParse3d.ErrorCode.get_validator_error_kind", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let validate_with_error_handler (typename: string) (fieldname: string) #nz #wk (#k1: parser_kind nz wk) #t1 (#p1: parser k1 t1) (#inv1: _) (#disj1: _) (#l1: eloc) (#ar: _) (v1: validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos0 = start_position in let h0 = HST.get () in [@@ (rename_let ("positionAfter" ^ typename)) ]let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else (error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_drop_true
val validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#disj: disjointness_pre) (#l: eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false)
val validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#disj: disjointness_pre) (#l: eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false)
let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 370, "start_col": 0, "start_line": 357 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t' p inv disj l true -> EverParse3d.Actions.Base.validate_with_action_t' p inv disj l false
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t'", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "Prims.unit", "EverParse3d.InputStream.Base.skip_if_success" ]
[]
false
false
false
false
false
let validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#disj: disjointness_pre) (#l: eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_weaken
val validate_weaken (#nz #wk: _) (#k: parser_kind nz wk) (#t: _) (#p: parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t p inv disj l ar) (#nz' #wk': _) (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar
val validate_weaken (#nz #wk: _) (#k: parser_kind nz wk) (#t: _) (#p: parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t p inv disj l ar) (#nz' #wk': _) (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar
let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 61, "end_line": 846, "start_col": 0, "start_line": 840 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l ar -> k': EverParse3d.Kinds.parser_kind nz' wk' {EverParse3d.Prelude.is_weaker_than k' k} -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_weaken p k') inv disj l ar
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Prelude.is_weaker_than", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "EverParse3d.Prelude.parse_weaken" ]
[]
false
false
false
false
false
let validate_weaken #nz #wk (#k: parser_kind nz wk) #t (#p: parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) #nz' #wk' (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar =
fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_impos
val validate_impos (_:unit) : validate_with_action_t (parse_impos ()) true_inv disjointness_trivial eloc_none true
val validate_impos (_:unit) : validate_with_action_t (parse_impos ()) true_inv disjointness_trivial eloc_none true
let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 105, "end_line": 869, "start_col": 0, "start_line": 868 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k')
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_impos ()) EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none true
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_impossible", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let validate_impos () =
fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_nlist_total_constant_size_mod_ok
val validate_nlist_total_constant_size_mod_ok (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: Type) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0)) (ensures (fun _ -> True))
val validate_nlist_total_constant_size_mod_ok (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: Type) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0)) (ensures (fun _ -> True))
let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 17, "end_line": 1216, "start_col": 0, "start_line": 1190 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv disj l true)
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_total_constant_size_no_read'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "EverParse3d.Prelude.nlist", "LowParse.Spec.Base.strengthen", "EverParse3d.Prelude.parse_nlist", "FStar.Int.Cast.uint32_to_uint64", "Prims.unit", "EverParse3d.Prelude.parse_nlist_total_fixed_size_kind_correct", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind_nlist", "Prims.l_and", "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", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "Prims.b2t", "Prims.op_LessThan", "Prims.int", "Prims.op_Modulus", "Prims.l_True" ]
[]
false
false
false
false
false
let validate_nlist_total_constant_size_mod_ok (n: U32.t) #wk (#k: parser_kind true wk) (#t: Type) (p: parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0)) (ensures (fun _ -> True)) =
[@@ inline_let ]let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_chan_inv_cond_stepT
val intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr)
val intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr)
let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 76, "end_line": 92, "start_col": 0, "start_line": 88 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Channel.Simplex.chan_val", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.chan_inv_step", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Memory.mem", "Prims.unit", "Steel.Utils.extract_pure", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) =
Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_nlist
val validate_nlist (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : validate_with_action_t (parse_nlist n p) inv disj l false
val validate_nlist (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : validate_with_action_t (parse_nlist n p) inv disj l false
let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 14, "end_line": 1145, "start_col": 0, "start_line": 1133 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.UInt32.t -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.validate_weaken", "EverParse3d.Kinds.WeakKindStrongPrefix", "LowParse.Spec.FLData.parse_fldata_kind", "FStar.UInt32.v", "LowParse.Spec.List.parse_list_kind", "Prims.list", "LowParse.Spec.FLData.parse_fldata", "LowParse.Spec.List.parse_list", "EverParse3d.Actions.Base.validate_fldata_consumes_all", "EverParse3d.Actions.Base.validate_list", "EverParse3d.Kinds.kind_nlist", "EverParse3d.Prelude.nlist", "EverParse3d.Prelude.parse_nlist" ]
[]
false
false
false
false
false
let validate_nlist (n: U32.t) #wk (#k: parser_kind true wk) #t (#p: parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) =
validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_nlist_constant_size_without_actions
val validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false)
val validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false)
let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 22, "end_line": 1333, "start_col": 0, "start_line": 1315 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n_is_const: Prims.bool -> n: FStar.UInt32.t -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "Prims.op_AmpAmp", "Prims.op_Equality", "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", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "Prims.op_LessThan", "EverParse3d.Actions.Base.validate_drop", "EverParse3d.Kinds.kind_nlist", "EverParse3d.Prelude.nlist", "EverParse3d.Prelude.parse_nlist", "EverParse3d.Actions.Base.validate_nlist_total_constant_size", "EverParse3d.Actions.Base.validate_nlist", "EverParse3d.Kinds.WeakKindStrongPrefix" ]
[]
false
false
false
false
false
let validate_nlist_constant_size_without_actions (n_is_const: bool) (n: U32.t) #wk (#k: parser_kind true wk) #t (#p: parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) =
if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list
val validate_list (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false
val validate_list (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false
let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 74, "end_line": 1044, "start_col": 0, "start_line": 1036 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t' p inv disj l ar -> EverParse3d.Actions.Base.validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t'", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.Actions.Base.validate_list'", "FStar.UInt64.t", "LowParse.Spec.List.parse_list_kind", "Prims.list", "LowParse.Spec.List.parse_list" ]
[]
false
false
false
false
false
let validate_list (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false =
fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_nlist_total_constant_size
val validate_nlist_total_constant_size (n_is_const: bool) (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: Type) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296)) (ensures (fun _ -> True))
val validate_nlist_total_constant_size (n_is_const: bool) (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: Type) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296)) (ensures (fun _ -> True))
let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 54, "end_line": 1311, "start_col": 0, "start_line": 1278 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n_is_const: Prims.bool -> n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv disj l true)
Prims.Pure
[]
[]
[ "Prims.bool", "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.op_Modulus", "FStar.UInt32.v", "EverParse3d.Actions.Base.validate_nlist_total_constant_size_mod_ok", "Prims.op_disEquality", "EverParse3d.Actions.Base.validate_nlist_constant_size_mod_ko", "EverParse3d.Actions.Base.validate_nlist_total_constant_size'", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind_nlist", "EverParse3d.Prelude.nlist", "EverParse3d.Prelude.parse_nlist", "Prims.l_and", "Prims.b2t", "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", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "Prims.op_LessThan", "Prims.l_True" ]
[]
false
false
false
false
false
let validate_nlist_total_constant_size (n_is_const: bool) (n: U32.t) #wk (#k: parser_kind true wk) (#t: Type) (p: parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296)) (ensures (fun _ -> True)) =
if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_with_success_action'
val validate_with_success_action' (name: string) (#nz #wk: _) (#k1: parser_kind nz wk) (#t1: _) (#p1: parser k1 t1) (#inv1 #disj1: _) (#l1: eloc) (v1: validate_with_action_t p1 inv1 disj1 l1 false) (#inv2 #disj2: _) (#l2: eloc) (#b: _) (a: action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
val validate_with_success_action' (name: string) (#nz #wk: _) (#k1: parser_kind nz wk) (#t1: _) (#p1: parser k1 t1) (#inv1 #disj1: _) (#l1: eloc) (v1: validate_with_action_t p1 inv1 disj1 l1 false) (#inv2 #disj2: _) (#l2: eloc) (#b: _) (a: action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 13, "end_line": 353, "start_col": 0, "start_line": 323 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 false -> a: EverParse3d.Actions.Base.action inv2 disj2 l2 b Prims.bool -> EverParse3d.Actions.Base.validate_with_action_t p1 (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.conj_disjointness disj1 disj2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.action", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_success", "Prims.op_Negation", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_action_failed", "FStar.UInt64.t", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.eloc_union" ]
[]
false
false
false
false
false
let validate_with_success_action' (name: string) #nz #wk (#k1: parser_kind nz wk) #t1 (#p1: parser k1 t1) (#inv1: _) (#disj1: _) (#l1: eloc) (v1: validate_with_action_t p1 inv1 disj1 l1 false) (#inv2: _) (#disj2: _) (#l2: eloc) #b (a: action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos0 = start_position in let h0 = HST.get () in [@@ (rename_let ("positionAfter" ^ name)) ]let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@@ (rename_let ("action_success_" ^ name)) ]let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_chan_inv_cond_eqT
val intro_chan_inv_cond_eqT (vs vr: chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True)
val intro_chan_inv_cond_eqT (vs vr: chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True)
let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 76, "end_line": 86, "start_col": 0, "start_line": 80 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend)
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "Steel.Channel.Simplex.chan_val", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Prims.eq2", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
false
true
false
false
false
let intro_chan_inv_cond_eqT (vs vr: chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) =
intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_with_comment
val validate_with_comment (c:string) (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) : validate_with_action_t p inv disj l allow_reading
val validate_with_comment (c:string) (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) : validate_with_action_t p inv disj l allow_reading
let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 61, "end_line": 1426, "start_col": 0, "start_line": 1419 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Prims.string -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "Prims.unit", "LowParse.Low.Base.comment" ]
[]
false
false
false
false
false
let validate_with_comment (c: string) #nz #wk (#k: parser_kind nz wk) #t (#p: parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar =
fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_total_constant_size_no_read'
val validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv disj l: _) : validate_with_action_t' p inv disj l true
val validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv disj l: _) : validate_with_action_t' p inv disj l true
let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 74, "end_line": 1170, "start_col": 0, "start_line": 1149 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: LowParse.Spec.Base.parser k t -> sz: FStar.UInt64.t -> u1471: u1475: Prims.unit { Mkparser_kind'?.parser_kind_high k == FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\ Mkparser_kind'?.parser_kind_low k == FStar.UInt64.v sz /\ Mkparser_kind'?.parser_kind_metadata k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserKindMetadataTotal } -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> EverParse3d.Actions.Base.validate_with_action_t' p inv disj l true
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.UInt64.t", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.add", "Prims.bool", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_not_enough_data", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.InputStream.Base.has", "LowParse.Spec.Base.parser_kind_prop_equiv", "EverParse3d.Actions.Base.validate_with_action_t'" ]
[]
false
false
false
false
false
let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_nlist_total_constant_size'
val validate_nlist_total_constant_size' (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296)) (ensures (fun _ -> True))
val validate_nlist_total_constant_size' (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296)) (ensures (fun _ -> True))
let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 100, "end_line": 1275, "start_col": 0, "start_line": 1256 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv disj l true)
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "Prims.op_Equality", "FStar.UInt32.rem", "FStar.UInt32.uint_to_t", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "FStar.UInt32.__uint_to_t", "EverParse3d.Actions.Base.validate_nlist_total_constant_size_mod_ok", "Prims.bool", "EverParse3d.Actions.Base.validate_nlist_constant_size_mod_ko", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt64.v", "FStar.Seq.Base.length", "EverParse3d.InputStream.Base.get_read", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Base.footprint", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.InputStream.Base.perm_footprint", "Prims.l_imp", "Prims.l_not", "EverParse3d.ErrorCode.is_error", "EverParse3d.ErrorCode.get_validator_error_pos", "EverParse3d.ErrorCode.is_success", "EverParse3d.Actions.Base.valid_length", "EverParse3d.Kinds.kind_nlist", "EverParse3d.Prelude.nlist", "EverParse3d.Prelude.parse_nlist", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "Prims.logical", "Prims.op_disEquality", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "FStar.Pervasives.Native.uu___is_None", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "EverParse3d.Actions.Base.valid_consumed", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "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", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "Prims.l_True" ]
[]
false
false
false
false
false
let validate_nlist_total_constant_size' (n: U32.t) #wk (#k: parser_kind true wk) #t (p: parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296)) (ensures (fun _ -> True)) =
fun ctxt error_handler_fn input start_position -> if n `U32.rem` (U32.uint_to_t k.LP.parser_kind_low) = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read_impos
val read_impos : leaf_reader (parse_impos())
val read_impos : leaf_reader (parse_impos())
let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim ()
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 19, "end_line": 1462, "start_col": 0, "start_line": 1459 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader (EverParse3d.Prelude.parse_impos ())
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "FStar.Pervasives.false_elim", "Prims.l_False", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.impos_kind", "EverParse3d.Prelude.parse_impos" ]
[]
false
false
false
false
false
let read_impos:leaf_reader (parse_impos ()) =
fun sl pos -> false_elim ()
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT8
val validate____UINT8 : validator parse____UINT8
val validate____UINT8 : validator parse____UINT8
let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 72, "end_line": 1469, "start_col": 0, "start_line": 1465 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT8
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT8", "EverParse3d.Prelude.___UINT8", "EverParse3d.Prelude.parse____UINT8", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT8:validator parse____UINT8 =
validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read_filter
val read_filter (#nz:_) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#[@@@erasable] p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f)
val read_filter (#nz:_) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#[@@@erasable] p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f)
let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 21, "end_line": 1456, "start_col": 0, "start_line": 1444 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p32: EverParse3d.Actions.Base.leaf_reader p -> f: (_: t -> Prims.bool) -> EverParse3d.Actions.Base.leaf_reader (EverParse3d.Prelude.parse_filter p f)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "Prims.unit", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining", "EverParse3d.Prelude.refine", "FStar.Pervasives.assert_norm", "Prims.eq2", "LowParse.Spec.Combinators.parse_filter_refine", "Prims._assert", "LowParse.Spec.Base.parser", "LowParse.Spec.Combinators.parse_filter_kind", "EverParse3d.Prelude.parse_filter", "LowParse.Spec.Combinators.parse_filter", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Kinds.filter_kind" ]
[]
false
false
false
false
false
let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) =
fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos
false
CQueue.fst
CQueue.enqueue
val enqueue (#a: Type) (x: t a) (l: Ghost.erased (v a)) (w: a) : Steel (Ghost.erased (v a)) (queue x l) (fun res -> queue x res) (requires (fun _ -> True)) (ensures (fun _ res _ -> datas res == datas l `L.append` [w]))
val enqueue (#a: Type) (x: t a) (l: Ghost.erased (v a)) (w: a) : Steel (Ghost.erased (v a)) (queue x l) (fun res -> queue x res) (requires (fun _ -> True)) (ensures (fun _ res _ -> datas res == datas l `L.append` [w]))
let enqueue #a x l w = queue_head_to_tail x l; let ptail0 = elim_queue_tail x l in let ptail = read (cllist_tail x) in let c = alloc_cell w (ccell_ptrvalue_null a) in let c0 = elim_ccell_ghost c in change_equal_slprop (vptr ptail0) (vptr ptail); write ptail c; change_equal_slprop (vptr ptail) (vptr ptail0); let l' = intro_llist_fragment_tail_snoc l (cllist_head x) ptail0 c0 in write (cllist_tail x) (ccell_next c); intro_queue_tail x l' (ccell_next c0); queue_tail_to_head x l'; return l'
{ "file_name": "share/steel/examples/steel/CQueue.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 11, "end_line": 1323, "start_col": 0, "start_line": 1306 }
module CQueue open CQueue.LList #set-options "--ide_id_info_off" //Re-define squash, since this module explicitly //replies on proving equalities of the form `t_of v == squash p` //which are delicate in the presence of optimizations that //unfold `Prims.squash (p /\ q)`to _:unit{p /\ q} //See Issue #2496 let squash (p:Type u#a) : Type0 = squash p (* BEGIN library *) let intro_vrewrite_no_norm (#opened:inames) (v: vprop) (#t: Type) (f: (t_of v) -> GTot t) : SteelGhost unit opened v (fun _ -> vrewrite v f) (fun _ -> True) (fun h _ h' -> h' (vrewrite v f) == f (h v)) = intro_vrewrite v f let elim_vrewrite_no_norm (#opened:inames) (v: vprop) (#t: Type) (f: ((t_of v) -> GTot t)) : SteelGhost unit opened (vrewrite v f) (fun _ -> v) (fun _ -> True) (fun h _ h' -> h (vrewrite v f) == f (h' v)) = elim_vrewrite v f let vconst_sel (#a: Type) (x: a) : Tot (selector a (hp_of emp)) = fun _ -> x [@@ __steel_reduce__] let vconst' (#a: Type) (x: a) : GTot vprop' = { hp = hp_of emp; t = a; sel = vconst_sel x; } [@@ __steel_reduce__] let vconst (#a: Type) (x: a) : Tot vprop = VUnit (vconst' x) let intro_vconst (#opened: _) (#a: Type) (x: a) : SteelGhost unit opened emp (fun _ -> vconst x) (fun _ -> True) (fun _ _ h' -> h' (vconst x) == x) = change_slprop_rel emp (vconst x) (fun _ y -> y == x) (fun _ -> ()) let elim_vconst (#opened: _) (#a: Type) (x: a) : SteelGhost unit opened (vconst x) (fun _ -> emp) (fun _ -> True) (fun h _ _ -> h (vconst x) == x) = change_slprop_rel (vconst x) emp (fun y _ -> y == x) (fun _ -> ()) let vpure_sel' (p: prop) : Tot (selector' (squash p) (Steel.Memory.pure p)) = fun (m: Steel.Memory.hmem (Steel.Memory.pure p)) -> pure_interp p m let vpure_sel (p: prop) : Tot (selector (squash p) (Steel.Memory.pure p)) = vpure_sel' p [@@ __steel_reduce__] let vpure' (p: prop) : GTot vprop' = { hp = Steel.Memory.pure p; t = squash p; sel = vpure_sel p; } [@@ __steel_reduce__] let vpure (p: prop) : Tot vprop = VUnit (vpure' p) let intro_vpure (#opened: _) (p: prop) : SteelGhost unit opened emp (fun _ -> vpure p) (fun _ -> p) (fun _ _ h' -> p) = change_slprop_rel emp (vpure p) (fun _ _ -> p) (fun m -> pure_interp p m) let elim_vpure (#opened: _) (p: prop) : SteelGhost unit opened (vpure p) (fun _ -> emp) (fun _ -> True) (fun _ _ _ -> p) = change_slprop_rel (vpure p) emp (fun _ _ -> p) (fun m -> pure_interp p m; reveal_emp (); intro_emp m) val intro_vdep2 (#opened:inames) (v: vprop) (q: vprop) (x: t_of v) (p: (t_of v -> Tot vprop)) : SteelGhost unit opened (v `star` q) (fun _ -> vdep v p) (requires (fun h -> q == p x /\ x == h v )) (ensures (fun h _ h' -> let x2 = h' (vdep v p) in q == p (h v) /\ dfst x2 == (h v) /\ dsnd x2 == (h q) )) let intro_vdep2 v q x p = intro_vdep v q p let vbind0_payload (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) (x: t_of a) : Tot vprop = vpure (t == t_of (b x)) `star` b x let vbind0_rewrite (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) (x: normal (t_of (vdep a (vbind0_payload a t b)))) : Tot t = snd (dsnd x) [@@__steel_reduce__; __reduce__] let vbind0 (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : Tot vprop = a `vdep` vbind0_payload a t b `vrewrite` vbind0_rewrite a t b let vbind_hp // necessary to hide the attribute on hp_of (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : Tot (slprop u#1) = hp_of (vbind0 a t b) let vbind_sel // same for hp_sel (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : GTot (selector t (vbind_hp a t b)) = sel_of (vbind0 a t b) [@@__steel_reduce__] let vbind' (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : GTot vprop' = { hp = vbind_hp a t b; t = t; sel = vbind_sel a t b; } [@@__steel_reduce__] let vbind (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : Tot vprop = VUnit (vbind' a t b) let intro_vbind (#opened: _) (a: vprop) (b' : vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : SteelGhost unit opened (a `star` b') (fun _ -> vbind a t b) (fun h -> t_of b' == t /\ b' == b (h a)) (fun h _ h' -> t_of b' == t /\ b' == b (h a) /\ h' (vbind a t b) == h b' ) = intro_vpure (t == t_of b'); intro_vdep a (vpure (t == t_of b') `star` b') (vbind0_payload a t b); intro_vrewrite (a `vdep` vbind0_payload a t b) (vbind0_rewrite a t b); change_slprop_rel (vbind0 a t b) (vbind a t b) (fun x y -> x == y) (fun _ -> ()) let elim_vbind (#opened: _) (a: vprop) (t: Type0) (b: (t_of a -> Tot vprop)) : SteelGhost (Ghost.erased (t_of a)) opened (vbind a t b) (fun res -> a `star` b (Ghost.reveal res)) (fun h -> True) (fun h res h' -> h' a == Ghost.reveal res /\ t == t_of (b (Ghost.reveal res)) /\ h' (b (Ghost.reveal res)) == h (vbind a t b) ) = change_slprop_rel (vbind a t b) (vbind0 a t b) (fun x y -> x == y) (fun _ -> ()); elim_vrewrite (a `vdep` vbind0_payload a t b) (vbind0_rewrite a t b); let res = elim_vdep a (vbind0_payload a t b) in change_equal_slprop (vbind0_payload a t b (Ghost.reveal res)) (vpure (t == t_of (b (Ghost.reveal res))) `star` b (Ghost.reveal res)); elim_vpure (t == t_of (b (Ghost.reveal res))); res let (==) (#a:_) (x y: a) : prop = x == y let snoc_inj (#a: Type) (hd1 hd2: list a) (tl1 tl2: a) : Lemma (requires (hd1 `L.append` [tl1] == hd2 `L.append` [tl2])) (ensures (hd1 == hd2 /\ tl1 == tl2)) [SMTPat (hd1 `L.append` [tl1]); SMTPat (hd2 `L.append` [tl2])] = L.lemma_snoc_unsnoc (hd1, tl1); L.lemma_snoc_unsnoc (hd2, tl2) [@"opaque_to_smt"] let unsnoc (#a: Type) (l: list a) : Pure (list a & a) (requires (Cons? l)) (ensures (fun (hd, tl) -> l == hd `L.append` [tl] /\ L.length hd < L.length l)) = L.lemma_unsnoc_snoc l; L.append_length (fst (L.unsnoc l)) [snd (L.unsnoc l)]; L.unsnoc l let unsnoc_hd (#a: Type) (l: list a) : Pure (list a) (requires (Cons? l)) (ensures (fun l' -> L.length l' < L.length l)) = fst (unsnoc l) let unsnoc_tl (#a: Type) (l: list a) : Pure (a) (requires (Cons? l)) (ensures (fun _ -> True)) = snd (unsnoc l) [@@"opaque_to_smt"] let snoc (#a: Type) (l: list a) (x: a) : Pure (list a) (requires True) (ensures (fun l' -> Cons? l' /\ unsnoc_hd l' == l /\ unsnoc_tl l' == x )) = let l' = L.snoc (l, x) in L.append_length l [x]; snoc_inj l (unsnoc_hd l') x (unsnoc_tl l'); l' let snoc_unsnoc (#a: Type) (l: list a) : Lemma (requires (Cons? l)) (ensures (snoc (unsnoc_hd l) (unsnoc_tl l) == l)) = () unfold let coerce (#a: Type) (x: a) (b: Type) : Pure b (requires (a == b)) (ensures (fun y -> a == b /\ x == y)) = x (* END library *) let t a = cllist_lvalue a let v (a: Type0) = list a let datas (#a: Type0) (l: v a) : Tot (list a) = l (* view from the tail *) let llist_fragment_tail_cons_data_refine (#a: Type) (l: Ghost.erased (list a) { Cons? (Ghost.reveal l) }) (d: a) : Tot prop = d == unsnoc_tl (Ghost.reveal l) [@@ __steel_reduce__] let llist_fragment_tail_cons_lvalue_payload (#a: Type) (l: Ghost.erased (list a) { Cons? (Ghost.reveal l) }) (c: ccell_lvalue a) : Tot vprop = vptr (ccell_data c) `vrefine` llist_fragment_tail_cons_data_refine l let ccell_is_lvalue_refine (a: Type) (c: ccell_ptrvalue a) : Tot prop = ccell_ptrvalue_is_null c == false [@@ __steel_reduce__ ] let llist_fragment_tail_cons_next_payload (#a: Type) (l: Ghost.erased (list a) { Cons? (Ghost.reveal l) }) (ptail: ref (ccell_ptrvalue a)) : Tot vprop = vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l [@@ __steel_reduce__ ] let llist_fragment_tail_cons_rewrite (#a: Type) (l: Ghost.erased (list a) { Cons? (Ghost.reveal l) }) (llist_fragment_tail: vprop { t_of llist_fragment_tail == ref (ccell_ptrvalue a) }) (x: normal (t_of (llist_fragment_tail `vdep` (llist_fragment_tail_cons_next_payload l)))) : Tot (ref (ccell_ptrvalue a)) = let (| _, (| c, _ |) |) = x in ccell_next c let rec llist_fragment_tail (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Pure vprop (requires True) (ensures (fun v -> t_of v == ref (ccell_ptrvalue a))) (decreases (Ghost.reveal (L.length l))) = if Nil? l then vconst phead else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead) let llist_fragment_tail_eq (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Lemma (llist_fragment_tail l phead == ( if Nil? l then vconst phead else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead) )) = assert_norm (llist_fragment_tail l phead == ( if Nil? l then vconst phead else llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead) )) let llist_fragment_tail_eq_cons (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : Lemma (requires (Cons? l)) (ensures (Cons? l /\ llist_fragment_tail l phead == ( llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead `vdep` llist_fragment_tail_cons_next_payload l `vrewrite` llist_fragment_tail_cons_rewrite l (llist_fragment_tail (Ghost.hide (unsnoc_hd (Ghost.reveal l))) phead) ))) = llist_fragment_tail_eq l phead unfold let sel_llist_fragment_tail (#a:Type) (#p:vprop) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_tail l phead) /\ True) }) : GTot (ref (ccell_ptrvalue a)) = coerce (h (llist_fragment_tail l phead)) (ref (ccell_ptrvalue a)) val intro_llist_fragment_tail_nil (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : SteelGhost unit opened emp (fun _ -> llist_fragment_tail l phead) (fun _ -> Nil? l) (fun _ _ h' -> sel_llist_fragment_tail l phead h' == phead) let intro_llist_fragment_tail_nil l phead = intro_vconst phead; change_equal_slprop (vconst phead) (llist_fragment_tail l phead) val elim_llist_fragment_tail_nil (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : SteelGhost unit opened (llist_fragment_tail l phead) (fun _ -> emp) (fun _ -> Nil? l) (fun h _ _ -> sel_llist_fragment_tail l phead h == phead) let elim_llist_fragment_tail_nil l phead = change_equal_slprop (llist_fragment_tail l phead) (vconst phead); elim_vconst phead val intro_llist_fragment_tail_snoc (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (ptail: Ghost.erased (ref (ccell_ptrvalue a))) (tail: Ghost.erased (ccell_lvalue a)) : SteelGhost (Ghost.erased (list a)) opened (llist_fragment_tail l phead `star` vptr ptail `star` vptr (ccell_data tail)) (fun res -> llist_fragment_tail res phead) (fun h -> sel_llist_fragment_tail l phead h == Ghost.reveal ptail /\ sel ptail h == Ghost.reveal tail ) (fun h res h' -> Ghost.reveal res == snoc (Ghost.reveal l) (sel (ccell_data tail) h) /\ sel_llist_fragment_tail res phead h' == ccell_next tail ) #push-options "--z3rlimit 16" let intro_llist_fragment_tail_snoc #_ #a l phead ptail tail = let d = gget (vptr (ccell_data tail)) in let l' : (l' : Ghost.erased (list a) { Cons? (Ghost.reveal l') }) = Ghost.hide (snoc (Ghost.reveal l) (Ghost.reveal d)) in intro_vrefine (vptr (ccell_data tail)) (llist_fragment_tail_cons_data_refine l'); intro_vrefine (vptr ptail) (ccell_is_lvalue_refine a); intro_vdep (vptr ptail `vrefine` ccell_is_lvalue_refine a) (vptr (ccell_data tail) `vrefine` llist_fragment_tail_cons_data_refine l') (llist_fragment_tail_cons_lvalue_payload l'); change_equal_slprop (llist_fragment_tail l phead) (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead); intro_vdep (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead) (vptr ptail `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l') (llist_fragment_tail_cons_next_payload l'); intro_vrewrite_no_norm (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l') (llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)); llist_fragment_tail_eq_cons l' phead; change_equal_slprop (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead `vdep` llist_fragment_tail_cons_next_payload l' `vrewrite` llist_fragment_tail_cons_rewrite l' (llist_fragment_tail (Ghost.hide (unsnoc_hd l')) phead)) (llist_fragment_tail l' phead); let g' = gget (llist_fragment_tail l' phead) in assert (Ghost.reveal g' == ccell_next tail); noop (); l' #pop-options [@@erasable] noeq type ll_unsnoc_t (a: Type) = { ll_unsnoc_l: list a; ll_unsnoc_ptail: ref (ccell_ptrvalue a); ll_unsnoc_tail: ccell_lvalue a; } val elim_llist_fragment_tail_snoc (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) : SteelGhost (ll_unsnoc_t a) opened (llist_fragment_tail l phead) (fun res -> llist_fragment_tail res.ll_unsnoc_l phead `star` vptr res.ll_unsnoc_ptail `star` vptr (ccell_data res.ll_unsnoc_tail)) (fun _ -> Cons? l) (fun h res h' -> Cons? l /\ Ghost.reveal res.ll_unsnoc_l == unsnoc_hd l /\ sel res.ll_unsnoc_ptail h' == res.ll_unsnoc_tail /\ sel (ccell_data res.ll_unsnoc_tail) h'== unsnoc_tl l /\ sel_llist_fragment_tail res.ll_unsnoc_l phead h' == res.ll_unsnoc_ptail /\ sel_llist_fragment_tail l phead h == (ccell_next res.ll_unsnoc_tail) ) #push-options "--z3rlimit 32" #restart-solver let elim_llist_fragment_tail_snoc #_ #a l phead = let l0 : (l0: Ghost.erased (list a) { Cons? l0 }) = Ghost.hide (Ghost.reveal l) in llist_fragment_tail_eq_cons l0 phead; change_equal_slprop (llist_fragment_tail l phead) (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0 `vrewrite` llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)); elim_vrewrite_no_norm (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead `vdep` llist_fragment_tail_cons_next_payload l0) (llist_fragment_tail_cons_rewrite l0 (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead)); let ptail = elim_vdep (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead) (llist_fragment_tail_cons_next_payload l0) in let ptail0 : Ghost.erased (ref (ccell_ptrvalue a)) = ptail in change_equal_slprop (llist_fragment_tail_cons_next_payload l0 (Ghost.reveal ptail)) (vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a `vdep` llist_fragment_tail_cons_lvalue_payload l0); let tail = elim_vdep (vptr (Ghost.reveal ptail0) `vrefine` ccell_is_lvalue_refine a) (llist_fragment_tail_cons_lvalue_payload l0) in elim_vrefine (vptr (Ghost.reveal ptail0)) (ccell_is_lvalue_refine a); let res = { ll_unsnoc_l = unsnoc_hd l0; ll_unsnoc_ptail = Ghost.reveal ptail0; ll_unsnoc_tail = Ghost.reveal tail; } in change_equal_slprop (vptr (Ghost.reveal ptail0)) (vptr res.ll_unsnoc_ptail); change_equal_slprop (llist_fragment_tail_cons_lvalue_payload l0 (Ghost.reveal tail)) (vptr (ccell_data res.ll_unsnoc_tail) `vrefine` llist_fragment_tail_cons_data_refine l0); elim_vrefine (vptr (ccell_data res.ll_unsnoc_tail)) (llist_fragment_tail_cons_data_refine l0); change_equal_slprop (llist_fragment_tail (Ghost.hide (unsnoc_hd l0)) phead) (llist_fragment_tail res.ll_unsnoc_l phead); res #pop-options let rec llist_fragment_tail_append (#opened: _) (#a: Type) (phead0: ref (ccell_ptrvalue a)) (l1: Ghost.erased (list a)) (phead1: Ghost.erased (ref (ccell_ptrvalue a))) (l2: Ghost.erased (list a)) : SteelGhost (Ghost.erased (list a)) opened (llist_fragment_tail l1 phead0 `star` llist_fragment_tail l2 phead1) (fun res -> llist_fragment_tail res phead0) (fun h -> Ghost.reveal phead1 == (sel_llist_fragment_tail l1 phead0) h ) (fun h res h' -> Ghost.reveal res == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\ (sel_llist_fragment_tail res phead0) h' == (sel_llist_fragment_tail l2 phead1) h ) (decreases (L.length (Ghost.reveal l2))) = let g1 = gget (llist_fragment_tail l1 phead0) in assert (Ghost.reveal phead1 == Ghost.reveal g1); if Nil? l2 then begin L.append_l_nil (Ghost.reveal l1); elim_llist_fragment_tail_nil l2 phead1; l1 end else begin let res = elim_llist_fragment_tail_snoc l2 (Ghost.reveal phead1) in let d = gget (vptr (ccell_data res.ll_unsnoc_tail)) in L.append_assoc (Ghost.reveal l1) (Ghost.reveal res.ll_unsnoc_l) [Ghost.reveal d]; let l3 = llist_fragment_tail_append phead0 l1 phead1 res.ll_unsnoc_l in intro_llist_fragment_tail_snoc l3 phead0 res.ll_unsnoc_ptail res.ll_unsnoc_tail end let queue_tail_refine (#a: Type) (tail1: ref (ccell_ptrvalue a)) (tail2: ref (ccell_ptrvalue a)) (tl: normal (t_of (vptr tail2))) : Tot prop = ccell_ptrvalue_is_null tl == true /\ tail1 == tail2 [@@__steel_reduce__] let queue_tail_dep2 (#a: Type) (x: t a) (l: Ghost.erased (list a)) (tail1: t_of (llist_fragment_tail l (cllist_head x))) (tail2: ref (ccell_ptrvalue a)) : Tot vprop = vptr tail2 `vrefine` queue_tail_refine tail1 tail2 [@@__steel_reduce__] let queue_tail_dep1 (#a: Type) (x: t a) (l: Ghost.erased (list a)) (tail1: t_of (llist_fragment_tail l (cllist_head x))) : Tot vprop = vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail1 [@@__steel_reduce__; __reduce__] let queue_tail (#a: Type) (x: t a) (l: Ghost.erased (list a)) : Tot vprop = llist_fragment_tail l (cllist_head x) `vdep` queue_tail_dep1 x l val intro_queue_tail (#opened: _) (#a: Type) (x: t a) (l: Ghost.erased (list a)) (tail: ref (ccell_ptrvalue a)) : SteelGhost unit opened (llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail) (fun _ -> queue_tail x l) (fun h -> sel_llist_fragment_tail l (cllist_head x) h == tail /\ sel (cllist_tail x) h == tail /\ ccell_ptrvalue_is_null (sel tail h) ) (fun _ _ _ -> True) let intro_queue_tail x l tail = intro_vrefine (vptr tail) (queue_tail_refine tail tail); intro_vdep2 (vptr (cllist_tail x)) (vptr tail `vrefine` queue_tail_refine tail tail) tail (queue_tail_dep2 x l tail); intro_vdep2 (llist_fragment_tail l (cllist_head x)) (vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail) tail (queue_tail_dep1 x l) val elim_queue_tail (#opened: _) (#a: Type) (x: t a) (l: Ghost.erased (list a)) : SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened (queue_tail x l) (fun tail -> llist_fragment_tail l (cllist_head x) `star` vptr (cllist_tail x) `star` vptr tail) (fun h -> True) (fun _ tail h -> sel_llist_fragment_tail l (cllist_head x) h == Ghost.reveal tail /\ sel (cllist_tail x) h == Ghost.reveal tail /\ ccell_ptrvalue_is_null (h (vptr tail)) ) let elim_queue_tail #_ #a x l = let tail0 = elim_vdep (llist_fragment_tail l (cllist_head x)) (queue_tail_dep1 x l) in let tail : Ghost.erased (ref (ccell_ptrvalue a)) = tail0 in change_equal_slprop (queue_tail_dep1 x l (Ghost.reveal tail0)) (vptr (cllist_tail x) `vdep` queue_tail_dep2 x l tail0); let tail2 = elim_vdep (vptr (cllist_tail x)) (queue_tail_dep2 x l tail0) in let tail3 : Ghost.erased (ref (ccell_ptrvalue a)) = tail2 in change_equal_slprop (queue_tail_dep2 x l tail0 (Ghost.reveal tail2)) (vptr tail3 `vrefine` queue_tail_refine tail0 tail3); elim_vrefine (vptr tail3) (queue_tail_refine tail0 tail3); change_equal_slprop (vptr tail3) (vptr tail); tail (* view from the head *) let llist_fragment_head_data_refine (#a: Type) (d: a) (c: vcell a) : Tot prop = c.vcell_data == d let llist_fragment_head_payload (#a: Type) (head: ccell_ptrvalue a) (d: a) (llist_fragment_head: (ref (ccell_ptrvalue a) -> ccell_ptrvalue a -> Tot vprop)) (x: t_of (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine d))) : Tot vprop = llist_fragment_head (ccell_next (fst x)) (snd x).vcell_next let rec llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Tot vprop (decreases (Ghost.reveal l)) = if Nil? l then vconst (phead, head) else vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l)))) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l)))) let t_of_llist_fragment_head (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Lemma (t_of (llist_fragment_head l phead head) == ref (ccell_ptrvalue a) & ccell_ptrvalue a) = () unfold let sel_llist_fragment_head (#a:Type) (#p:vprop) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) (h: rmem p { FStar.Tactics.with_tactic selector_tactic (can_be_split p (llist_fragment_head l phead head) /\ True) }) : GTot (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = coerce (h (llist_fragment_head l phead head)) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) val intro_llist_fragment_head_nil (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : SteelGhost unit opened emp (fun _ -> llist_fragment_head l phead head) (fun _ -> Nil? l) (fun _ _ h' -> sel_llist_fragment_head l phead head h' == (phead, head)) let intro_llist_fragment_head_nil l phead head = intro_vconst (phead, head); change_equal_slprop (vconst (phead, head)) (llist_fragment_head l phead head) val elim_llist_fragment_head_nil (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : SteelGhost unit opened (llist_fragment_head l phead head) (fun _ -> emp) (fun _ -> Nil? l) (fun h _ _ -> sel_llist_fragment_head l phead head h == (phead, head)) let elim_llist_fragment_head_nil l phead head = change_equal_slprop (llist_fragment_head l phead head) (vconst (phead, head)); elim_vconst (phead, head) let llist_fragment_head_eq_cons (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : Lemma (requires (Cons? (Ghost.reveal l))) (ensures ( llist_fragment_head l phead head == vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l)))) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l)))) )) = assert_norm (llist_fragment_head l phead head == ( if Nil? l then vconst (phead, head) else vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd (Ghost.reveal l)))) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd (Ghost.reveal l)) (llist_fragment_head (L.tl (Ghost.reveal l)))) )) val intro_llist_fragment_head_cons (#opened: _) (#a: Type) (phead: ref (ccell_ptrvalue a)) (head: ccell_lvalue a) (next: (ccell_ptrvalue a)) (tl: Ghost.erased (list a)) : SteelGhost (Ghost.erased (list a)) opened (ccell head `star` llist_fragment_head tl (ccell_next head) next) (fun res -> llist_fragment_head res phead head) (fun h -> (h (ccell head)).vcell_next == next) (fun h res h' -> Ghost.reveal res == (h (ccell head)).vcell_data :: Ghost.reveal tl /\ h' (llist_fragment_head res phead head) == h (llist_fragment_head tl (ccell_next head) next) ) let intro_llist_fragment_head_cons #_ #a phead head next tl = let vc = gget (ccell head) in let l' : (l' : Ghost.erased (list a) { Cons? l' }) = Ghost.hide (vc.vcell_data :: tl) in intro_ccell_is_lvalue head; intro_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l')); intro_vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l'))) (llist_fragment_head tl (ccell_next head) next) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l'))); llist_fragment_head_eq_cons l' phead head; change_equal_slprop (vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l'))) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd l') (llist_fragment_head (L.tl l')))) (llist_fragment_head l' phead head); l' [@@erasable] noeq type ll_uncons_t (a: Type) = { ll_uncons_pnext: Ghost.erased (ref (ccell_ptrvalue a)); ll_uncons_next: Ghost.erased (ccell_ptrvalue a); ll_uncons_tl: Ghost.erased (list a); } val elim_llist_fragment_head_cons (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : SteelGhost (ll_uncons_t a) opened (llist_fragment_head l phead head) (fun res -> ccell head `star` llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) (fun _ -> Cons? (Ghost.reveal l)) (fun h res h' -> ccell_ptrvalue_is_null head == false /\ Ghost.reveal l == (h' (ccell head)).vcell_data :: Ghost.reveal res.ll_uncons_tl /\ Ghost.reveal res.ll_uncons_pnext == ccell_next head /\ Ghost.reveal res.ll_uncons_next == (h' (ccell head)).vcell_next /\ h' (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next) == h (llist_fragment_head l phead head) ) let elim_llist_fragment_head_cons #_ #a l0 phead head = let l : (l : Ghost.erased (list a) { Cons? l }) = l0 in change_equal_slprop (llist_fragment_head l0 phead head) (llist_fragment_head l phead head); llist_fragment_head_eq_cons l phead head; change_equal_slprop (llist_fragment_head l phead head) (vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l))) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)))); let x = elim_vbind (ccell_is_lvalue head `star` (ccell head `vrefine` llist_fragment_head_data_refine (L.hd l))) (ref (ccell_ptrvalue a) & ccell_ptrvalue a) (llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l))) in let head2 = gget (ccell_is_lvalue head) in elim_ccell_is_lvalue head; elim_vrefine (ccell head) (llist_fragment_head_data_refine (L.hd l)); let vhead2 = gget (ccell head) in let res = { ll_uncons_pnext = ccell_next head2; ll_uncons_next = vhead2.vcell_next; ll_uncons_tl = L.tl l; } in change_equal_slprop (llist_fragment_head_payload head (L.hd l) (llist_fragment_head (L.tl l)) (Ghost.reveal x)) (llist_fragment_head res.ll_uncons_tl res.ll_uncons_pnext res.ll_uncons_next); res let rec llist_fragment_head_append (#opened: _) (#a: Type) (l1: Ghost.erased (list a)) (phead1: ref (ccell_ptrvalue a)) (head1: ccell_ptrvalue a) (l2: Ghost.erased (list a)) (phead2: ref (ccell_ptrvalue a)) (head2: ccell_ptrvalue a) : SteelGhost (Ghost.erased (list a)) opened (llist_fragment_head l1 phead1 head1 `star` llist_fragment_head l2 phead2 head2) (fun l -> llist_fragment_head l phead1 head1) (fun h -> sel_llist_fragment_head l1 phead1 head1 h == (Ghost.reveal phead2, Ghost.reveal head2)) (fun h l h' -> Ghost.reveal l == Ghost.reveal l1 `L.append` Ghost.reveal l2 /\ h' (llist_fragment_head l phead1 head1) == h (llist_fragment_head l2 phead2 head2) ) (decreases (Ghost.reveal l1)) = if Nil? l1 then begin elim_llist_fragment_head_nil l1 phead1 head1; change_equal_slprop (llist_fragment_head l2 phead2 head2) (llist_fragment_head l2 phead1 head1); l2 end else begin let u = elim_llist_fragment_head_cons l1 phead1 head1 in let head1' : Ghost.erased (ccell_lvalue a) = head1 in let l3 = llist_fragment_head_append u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next l2 phead2 head2 in change_equal_slprop (llist_fragment_head l3 u.ll_uncons_pnext u.ll_uncons_next) (llist_fragment_head l3 (ccell_next head1') u.ll_uncons_next); change_equal_slprop (ccell head1) (ccell head1'); let l4 = intro_llist_fragment_head_cons phead1 head1' u.ll_uncons_next l3 in change_equal_slprop (llist_fragment_head l4 phead1 head1') (llist_fragment_head l4 phead1 head1); l4 end let rec llist_fragment_head_to_tail (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : SteelGhost (Ghost.erased (ref (ccell_ptrvalue a))) opened (vptr phead `star` llist_fragment_head l phead head) (fun res -> llist_fragment_tail l phead `star` vptr res) (fun h -> h (vptr phead) == head) (fun h res h' -> let v = sel_llist_fragment_head l phead head h in fst v == Ghost.reveal res /\ fst v == sel_llist_fragment_tail l phead h' /\ snd v == h' (vptr res) ) (decreases (L.length (Ghost.reveal l))) = if Nil? l then begin let ptail = Ghost.hide phead in let gh = gget (vptr phead) in assert (Ghost.reveal gh == head); elim_llist_fragment_head_nil l phead head; intro_llist_fragment_tail_nil l phead; change_equal_slprop (vptr phead) (vptr ptail); ptail end else begin intro_llist_fragment_tail_nil [] phead; change_equal_slprop (vptr phead) (vptr (Ghost.reveal (Ghost.hide phead))); let uc = elim_llist_fragment_head_cons l phead head in let head' = elim_ccell_ghost head in change_equal_slprop (vptr (ccell_next head')) (vptr uc.ll_uncons_pnext); let lc = intro_llist_fragment_tail_snoc [] phead phead head' in let ptail = llist_fragment_head_to_tail uc.ll_uncons_tl uc.ll_uncons_pnext uc.ll_uncons_next in let l' = llist_fragment_tail_append phead lc uc.ll_uncons_pnext uc.ll_uncons_tl in change_equal_slprop (llist_fragment_tail l' phead) (llist_fragment_tail l phead); ptail end #push-options "--z3rlimit 16" #restart-solver let rec llist_fragment_tail_to_head (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (ptail: ref (ccell_ptrvalue a)) : SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened (llist_fragment_tail l phead `star` vptr ptail) (fun head -> vptr phead `star` llist_fragment_head l phead (Ghost.reveal head)) (fun h -> Ghost.reveal ptail == sel_llist_fragment_tail l phead h) (fun h head h' -> let v = sel_llist_fragment_head l phead head h' in fst v == ptail /\ snd v == h (vptr ptail) /\ h' (vptr phead) == Ghost.reveal head ) (decreases (L.length (Ghost.reveal l))) = if Nil? l then begin let g = gget (llist_fragment_tail l phead) in assert (Ghost.reveal g == ptail); elim_llist_fragment_tail_nil l phead; change_equal_slprop (vptr ptail) (vptr phead); let head = gget (vptr phead) in intro_llist_fragment_head_nil l phead head; head end else begin let us = elim_llist_fragment_tail_snoc l phead in let tail = gget (vptr ptail) in assert (ccell_next us.ll_unsnoc_tail == ptail); intro_llist_fragment_head_nil [] (ccell_next us.ll_unsnoc_tail) tail; change_equal_slprop (vptr ptail) (vptr (ccell_next us.ll_unsnoc_tail)); intro_ccell us.ll_unsnoc_tail; let lc = intro_llist_fragment_head_cons us.ll_unsnoc_ptail us.ll_unsnoc_tail tail [] in let head = llist_fragment_tail_to_head us.ll_unsnoc_l phead us.ll_unsnoc_ptail in let g = gget (llist_fragment_head us.ll_unsnoc_l phead head) in let g : Ghost.erased (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = Ghost.hide (Ghost.reveal g) in assert (Ghost.reveal g == (Ghost.reveal us.ll_unsnoc_ptail, Ghost.reveal us.ll_unsnoc_tail)); let l' = llist_fragment_head_append us.ll_unsnoc_l phead head lc us.ll_unsnoc_ptail us.ll_unsnoc_tail in change_equal_slprop (llist_fragment_head l' phead head) (llist_fragment_head l phead head); head end #pop-options val llist_fragment_head_is_nil (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) : SteelGhost unit opened (llist_fragment_head l phead head) (fun _ -> llist_fragment_head l phead head) (fun h -> ccell_ptrvalue_is_null (snd (sel_llist_fragment_head l phead head h)) == true) (fun h _ h' -> Nil? l == ccell_ptrvalue_is_null head /\ h' (llist_fragment_head l phead head) == h (llist_fragment_head l phead head) ) let llist_fragment_head_is_nil l phead head = if Nil? l then begin elim_llist_fragment_head_nil l phead head; assert (ccell_ptrvalue_is_null head == true); intro_llist_fragment_head_nil l phead head end else begin let r = elim_llist_fragment_head_cons l phead head in let head2 : ccell_lvalue _ = head in change_equal_slprop (llist_fragment_head r.ll_uncons_tl r.ll_uncons_pnext r.ll_uncons_next) (llist_fragment_head r.ll_uncons_tl (ccell_next head2) r.ll_uncons_next); change_equal_slprop (ccell head) (ccell head2); let l' = intro_llist_fragment_head_cons phead head2 r.ll_uncons_next r.ll_uncons_tl in change_equal_slprop (llist_fragment_head l' phead head2) (llist_fragment_head l phead head) end val llist_fragment_head_cons_change_phead (#opened: _) (#a: Type) (l: Ghost.erased (list a)) (phead: ref (ccell_ptrvalue a)) (head: ccell_ptrvalue a) (phead' : ref (ccell_ptrvalue a)) : SteelGhost unit opened (llist_fragment_head l phead head) (fun _ -> llist_fragment_head l phead' head) (fun _ -> Cons? l) (fun h _ h' -> h' (llist_fragment_head l phead' head) == h (llist_fragment_head l phead head)) let llist_fragment_head_cons_change_phead l phead head phead' = let u = elim_llist_fragment_head_cons l phead head in let head2 : ccell_lvalue _ = head in change_equal_slprop (ccell head) (ccell head2); change_equal_slprop (llist_fragment_head u.ll_uncons_tl u.ll_uncons_pnext u.ll_uncons_next) (llist_fragment_head u.ll_uncons_tl (ccell_next head2) u.ll_uncons_next); let l' = intro_llist_fragment_head_cons phead' head2 u.ll_uncons_next u.ll_uncons_tl in change_equal_slprop (llist_fragment_head l' phead' head2) (llist_fragment_head l phead' head) let queue_head_refine (#a: Type) (x: t a) (l: Ghost.erased (list a)) (hd: ccell_ptrvalue a) (ptl: t_of (llist_fragment_head l (cllist_head x) hd)) (tl: ref (ccell_ptrvalue a)) : Tot prop = let ptl : (ref (ccell_ptrvalue a) & ccell_ptrvalue a) = ptl in tl == fst ptl /\ ccell_ptrvalue_is_null (snd ptl) == true let queue_head_dep1 (#a: Type) (x: t a) (l: Ghost.erased (list a)) (hd: ccell_ptrvalue a) (ptl: t_of (llist_fragment_head l (cllist_head x) hd)) : Tot vprop = vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl let queue_head_dep2 (#a: Type) (x: t a) (l: Ghost.erased (list a)) (hd: ccell_ptrvalue a) : Tot vprop = llist_fragment_head l (cllist_head x) hd `vdep` queue_head_dep1 x l hd [@@__reduce__] let queue_head (#a: Type) (x: t a) (l: Ghost.erased (list a)) : Tot vprop = vptr (cllist_head x) `vdep` queue_head_dep2 x l val intro_queue_head (#opened: _) (#a: Type) (x: t a) (l: Ghost.erased (list a)) (hd: Ghost.erased (ccell_ptrvalue a)) : SteelGhost unit opened (vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x)) (fun _ -> queue_head x l) (fun h -> ( let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in sel (cllist_head x) h == Ghost.reveal hd /\ sel (cllist_tail x) h == fst frag /\ ccell_ptrvalue_is_null (snd frag) == true )) (fun _ _ _ -> True) let intro_queue_head #_ #a x l hd = let ptl = gget (llist_fragment_head l (cllist_head x) hd) in intro_vrefine (vptr (cllist_tail x)) (queue_head_refine x l hd ptl); assert_norm (vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl == queue_head_dep1 x l hd ptl); intro_vdep (llist_fragment_head l (cllist_head x) hd) (vptr (cllist_tail x) `vrefine` queue_head_refine x l hd ptl) (queue_head_dep1 x l hd); intro_vdep (vptr (cllist_head x)) (llist_fragment_head l (cllist_head x) hd `vdep` queue_head_dep1 x l hd) (queue_head_dep2 x l) val elim_queue_head (#opened: _) (#a: Type) (x: t a) (l: Ghost.erased (list a)) : SteelGhost (Ghost.erased (ccell_ptrvalue a)) opened (queue_head x l) (fun hd -> vptr (cllist_head x) `star` llist_fragment_head l (cllist_head x) hd `star` vptr (cllist_tail x)) (fun _ -> True) (fun _ hd h -> ( let frag = (sel_llist_fragment_head l (cllist_head x) hd) h in sel (cllist_head x) h == Ghost.reveal hd /\ sel (cllist_tail x) h == fst frag /\ ccell_ptrvalue_is_null (snd frag) == true )) let elim_queue_head #_ #a x l = let hd = elim_vdep (vptr (cllist_head x)) (queue_head_dep2 x l) in let ptl = elim_vdep (llist_fragment_head l (cllist_head x) hd) (queue_head_dep1 x l hd) in elim_vrefine (vptr (cllist_tail x)) (queue_head_refine x l hd ptl); hd let queue_head_to_tail (#opened: _) (#a: Type) (x: t a) (l: Ghost.erased (list a)) : SteelGhostT unit opened (queue_head x l) (fun _ -> queue_tail x l) = let hd = elim_queue_head x l in let tl = llist_fragment_head_to_tail l (cllist_head x) hd in intro_queue_tail x l tl let queue_tail_to_head (#opened: _) (#a: Type) (x: t a) (l: Ghost.erased (list a)) : SteelGhostT unit opened (queue_tail x l) (fun _ -> queue_head x l) = let tl = elim_queue_tail x l in let hd = llist_fragment_tail_to_head l (cllist_head x) tl in intro_queue_head x l hd (* We choose the head representation, since queue_is_empty and dequeue need the head representation, but only enqueue needs the tail representation. *) [@@__reduce__] let queue x l = queue_head x l let create_queue a = let head = ccell_ptrvalue_null a in let tail : ref (ccell_ptrvalue a) = null in let l0 = alloc_llist head tail in let l = elim_cllist l0 in write (cllist_tail l) (cllist_head l); intro_llist_fragment_head_nil [] (cllist_head l) (Ghost.reveal (Ghost.hide head)); intro_queue_head l [] head; let res : (t a & Ghost.erased (v a)) = (l0, Ghost.hide []) in change_equal_slprop (queue_head l []) (queue (fst res) (snd res)); return res
{ "checked_file": "/", "dependencies": [ "Steel.Memory.fsti.checked", "prims.fst.checked", "FStar.Tactics.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "CQueue.LList.fsti.checked" ], "interface_file": true, "source_file": "CQueue.fst" }
[ { "abbrev": false, "full_module": "CQueue.LList", "short_module": null }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: CQueue.t a -> l: FStar.Ghost.erased (CQueue.v a) -> w: a -> Steel.Effect.Steel (FStar.Ghost.erased (CQueue.v a))
Steel.Effect.Steel
[]
[]
[ "CQueue.t", "FStar.Ghost.erased", "CQueue.v", "Steel.Effect.Atomic.return", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.vdep", "Steel.Reference.vptrp", "CQueue.Cell.ccell_ptrvalue", "CQueue.LList.cllist_head", "Steel.FractionalPermission.full_perm", "CQueue.queue_head_dep2", "Steel.Effect.Common.vprop", "Prims.unit", "CQueue.queue_tail_to_head", "CQueue.intro_queue_tail", "CQueue.Cell.ccell_next", "FStar.Ghost.reveal", "CQueue.Cell.ccell_lvalue", "Steel.Reference.write", "Steel.Reference.ref", "CQueue.LList.cllist_tail", "Prims.list", "CQueue.intro_llist_fragment_tail_snoc", "Steel.Effect.Atomic.change_equal_slprop", "Steel.Reference.vptr", "CQueue.Cell.elim_ccell_ghost", "CQueue.Cell.alloc_cell", "CQueue.Cell.ccell_ptrvalue_null", "Steel.Reference.read", "CQueue.elim_queue_tail", "CQueue.queue_head_to_tail" ]
[]
false
true
false
false
false
let enqueue #a x l w =
queue_head_to_tail x l; let ptail0 = elim_queue_tail x l in let ptail = read (cllist_tail x) in let c = alloc_cell w (ccell_ptrvalue_null a) in let c0 = elim_ccell_ghost c in change_equal_slprop (vptr ptail0) (vptr ptail); write ptail c; change_equal_slprop (vptr ptail) (vptr ptail0); let l' = intro_llist_fragment_tail_snoc l (cllist_head x) ptail0 c0 in write (cllist_tail x) (ccell_next c); intro_queue_tail x l' (ccell_next c0); queue_tail_to_head x l'; return l'
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT8
val read____UINT8 : leaf_reader parse____UINT8
val read____UINT8 : leaf_reader parse____UINT8
let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 48, "end_line": 1496, "start_col": 0, "start_line": 1494 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT8
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Int.read_u8", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT8", "EverParse3d.Prelude.___UINT8", "EverParse3d.Prelude.parse____UINT8" ]
[]
false
false
false
false
false
let read____UINT8:leaf_reader parse____UINT8 =
lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_in_state
val intro_in_state (r: ref chan_val) (p: prot) (v: chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p)
val intro_in_state (r: ref chan_val) (p: prot) (v: chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p)
let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v)
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 83, "end_line": 163, "start_col": 0, "start_line": 160 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
r: Steel.HigherReference.ref Steel.Channel.Simplex.chan_val -> p: Steel.Channel.Simplex.prot -> v: Steel.Channel.Simplex.chan_val_p p -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.HigherReference.ref", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_val_p", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.in_state_slprop", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Steel.Channel.Simplex.in_state_prop", "Steel.Channel.Simplex.in_state" ]
[]
false
true
false
false
false
let intro_in_state (r: ref chan_val) (p: prot) (v: chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) =
intro_pure (in_state_prop p v); intro_exists v (fun (v: chan_val) -> (pts_to r half v) `star` (in_state_slprop p v))
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.next_trace_st
val next_trace_st (#p: _) (vr vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg)
val next_trace_st (#p: _) (vr vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg)
let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 13, "end_line": 315, "start_col": 0, "start_line": 307 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
vr: Steel.Channel.Simplex.chan_val -> vs: Steel.Channel.Simplex.chan_val -> tr: Steel.Channel.Protocol.partial_trace_of p -> Steel.Effect.Steel (Steel.Channel.Protocol.extension_of tr)
Steel.Effect.Steel
[]
[]
[ "Steel.Channel.Protocol.protocol", "Prims.unit", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Protocol.partial_trace_of", "Steel.Effect.Atomic.return", "Steel.Channel.Protocol.extension_of", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "Steel.Effect.Common.vprop", "Steel.Effect.Common.req", "Steel.Effect.Common.rm", "Steel.Channel.Simplex.next_trace", "Steel.Effect.Atomic.elim_pure", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Channel.Simplex.chan_inv_step", "Steel.Effect.Common.emp", "Steel.Effect.Common.rmem", "Prims.eq2", "Steel.Channel.Protocol.until", "Steel.Channel.Simplex.step", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg" ]
[]
false
true
false
false
false
let next_trace_st #p (vr: chan_val) (vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) =
elim_pure (chan_inv_step_p vr vs); let ts:extension_of tr = next_trace vr vs tr () () in return ts
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list'
val validate_list' (#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ (loc_not_unused_in h) `loc_includes` (app_loc ctxt l) /\ (app_loc ctxt l) `loc_disjoint` (I.footprint sl) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt l) /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h))) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ (let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` (Seq.slice s (Seq.length s - Seq.length s') (Seq.length s))) /\ (match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then (I.get_remaining sl h') `Seq.equal` (Seq.slice s len (Seq.length s)) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed) /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies ((app_loc ctxt l) `B.loc_union` (I.perm_footprint sl)) h h'))
val validate_list' (#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ (loc_not_unused_in h) `loc_includes` (app_loc ctxt l) /\ (app_loc ctxt l) `loc_disjoint` (I.footprint sl) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt l) /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h))) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ (let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` (Seq.slice s (Seq.length s - Seq.length s') (Seq.length s))) /\ (match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then (I.get_remaining sl h') `Seq.equal` (Seq.slice s len (Seq.length s)) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed) /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies ((app_loc ctxt l) `B.loc_union` (I.perm_footprint sl)) h h'))
let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 13, "end_line": 1032, "start_col": 0, "start_line": 970 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t' p inv disj l ar -> ctxt: EverParse3d.Actions.Base.app_ctxt -> error_handler_fn: EverParse3d.Actions.Base.error_handler -> sl: EverParse3d.Actions.Base.input_buffer_t -> sl_len: EverParse3d.InputStream.Base.tlen sl -> pos: EverParse3d.ErrorCode.pos_t -> FStar.HyperStack.ST.Stack FStar.UInt64.t
FStar.HyperStack.ST.Stack
[]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t'", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "Prims.unit", "LowParse.Spec.Base.parser_kind_prop_equiv", "Prims.list", "LowParse.Spec.List.parse_list_kind", "LowParse.Spec.List.parse_list", "Prims._assert", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "EverParse3d.InputStream.Base.perm_footprint", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "C.Loops.do_while", "EverParse3d.Actions.Base.validate_list_inv", "EverParse3d.Actions.Base.validate_list_body", "EverParse3d.InputStream.Base.live_not_unused_in", "FStar.Ghost.erased", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.mbuffer", "Prims.l_and", "Prims.eq2", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.v", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Prims.b2t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "LowStar.Monotonic.Buffer.fresh_frame_modifies", "FStar.HyperStack.ST.push_frame", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Base.footprint", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "EverParse3d.InputStream.Base.live", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.Seq.Base.length", "EverParse3d.InputStream.Base.get_read", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Base.parse", "EverParse3d.ErrorCode.is_success", "LowParse.Spec.Base.consumed_length", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "Prims.logical", "Prims.l_imp", "EverParse3d.ErrorCode.get_validator_error_pos" ]
[]
false
true
false
false
false
let validate_list' (#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ (loc_not_unused_in h) `loc_includes` (app_loc ctxt l) /\ (app_loc ctxt l) `loc_disjoint` (I.footprint sl) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt l) /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h))) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ (let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` (Seq.slice s (Seq.length s - Seq.length s') (Seq.length s))) /\ (match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then (I.get_remaining sl h') `Seq.equal` (Seq.slice s len (Seq.length s)) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed) /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies ((app_loc ctxt l) `B.loc_union` (I.perm_footprint sl)) h h')) =
let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies ((app_loc ctxt l) `B.loc_union` (I.perm_footprint sl)) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_filter
val validate_filter (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : validate_with_action_t (p `parse_filter` f) inv disj l false
val validate_filter (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : validate_with_action_t (p `parse_filter` f) inv disj l false
let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 776, "start_col": 0, "start_line": 753 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name: Prims.string -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l true -> r: EverParse3d.Actions.Base.leaf_reader p -> f: (_: t -> Prims.bool) -> cr: Prims.string -> cf: Prims.string -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_filter p f) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_error", "FStar.UInt64.t", "EverParse3d.ErrorCode.check_constraint_ok", "Prims.unit", "LowStar.Comment.comment", "FStar.Pervasives.normalize_term", "Prims.op_Hat", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining" ]
[]
false
false
false
false
false
let validate_filter (name: string) #nz (#k: parser_kind nz _) (#t: _) (#p: parser k t) #inv #disj #l (v: validate_with_action_t p inv disj l true) (r: leaf_reader p) (f: (t -> bool)) (cr: string) (cf: string) =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@@ (rename_let ("positionAfter" ^ name)) ]let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else (LowStar.Comment.comment cr; [@@ (rename_let ("" ^ name)) ]let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^ cf)); [@@ (rename_let (name ^ "ConstraintIsOk")) ]let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT32BE
val validate____UINT32BE : validator parse____UINT32BE
val validate____UINT32BE : validator parse____UINT32BE
let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 75, "end_line": 1527, "start_col": 0, "start_line": 1523 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT32BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT32BE", "EverParse3d.Prelude.___UINT32BE", "EverParse3d.Prelude.parse____UINT32BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT32BE:validator parse____UINT32BE =
validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT8BE
val validate____UINT8BE : validator parse____UINT8BE
val validate____UINT8BE : validator parse____UINT8BE
let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 74, "end_line": 1503, "start_col": 0, "start_line": 1499 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT8BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT8BE", "EverParse3d.Prelude.___UINT8BE", "EverParse3d.Prelude.parse____UINT8BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT8BE:validator parse____UINT8BE =
validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_weaken_inv_loc
val validate_weaken_inv_loc (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) ([@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) ([@@@erasable] disj':disjointness_pre { disj' `imp_disjointness` disj }) ([@@@erasable] l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t p inv' disj' l' allow_reading)
val validate_weaken_inv_loc (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#allow_reading:bool) ([@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) ([@@@erasable] disj':disjointness_pre { disj' `imp_disjointness` disj }) ([@@@erasable] l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l allow_reading) : Tot (validate_with_action_t p inv' disj' l' allow_reading)
let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 1437, "start_col": 0, "start_line": 1429 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
inv': EverParse3d.Actions.Base.slice_inv{EverParse3d.Actions.Base.inv_implies inv' inv} -> disj': EverParse3d.Actions.Base.disjointness_pre {EverParse3d.Actions.Base.imp_disjointness disj' disj} -> l': EverParse3d.Actions.Base.eloc{EverParse3d.Actions.Base.eloc_includes l' l} -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t p inv' disj' l' allow_reading
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.inv_implies", "EverParse3d.Actions.Base.imp_disjointness", "EverParse3d.Actions.Base.eloc_includes", "EverParse3d.Actions.Base.validate_with_action_t" ]
[]
false
false
false
false
false
let validate_weaken_inv_loc #nz #wk (#k: parser_kind nz wk) #t (#p: parser k t) #inv #disj (#l: eloc) #ar (inv': slice_inv{inv' `inv_implies` inv}) (disj': _{disj' `imp_disjointness` disj}) (l': eloc{l' `eloc_includes` l}) (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) =
v
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT16BE
val read____UINT16BE : leaf_reader parse____UINT16BE
val read____UINT16BE : leaf_reader parse____UINT16BE
let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 49, "end_line": 1520, "start_col": 0, "start_line": 1518 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT16BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u16_kind", "FStar.UInt16.t", "LowParse.Spec.Int.parse_u16", "LowParse.Low.Int.read_u16", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT16BE", "EverParse3d.Prelude.___UINT16BE", "EverParse3d.Prelude.parse____UINT16BE" ]
[]
false
false
false
false
false
let read____UINT16BE:leaf_reader parse____UINT16BE =
lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT64BE
val validate____UINT64BE : validator parse____UINT64BE
val validate____UINT64BE : validator parse____UINT64BE
let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 75, "end_line": 1539, "start_col": 0, "start_line": 1535 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT64BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT64BE", "EverParse3d.Prelude.___UINT64BE", "EverParse3d.Prelude.parse____UINT64BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT64BE:validator parse____UINT64BE =
validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _)
false
FStar.DM4F.IntStoreExcFixed.fst
FStar.DM4F.IntStoreExcFixed.return_is
val return_is (a: Type) (x: a) : int_store_exc a
val return_is (a: Type) (x: a) : int_store_exc a
let return_is (a:Type) (x:a) : int_store_exc a = fun store -> Some x, store
{ "file_name": "examples/dm4free/FStar.DM4F.IntStoreExcFixed.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 75, "end_line": 22, "start_col": 0, "start_line": 22 }
(* 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.DM4F.IntStoreExcFixed open FStar.DM4F.Heap.IntStoreFixed (* TODO : Try to use [either a exn] instead of [option] *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntStoreExcFixed.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> x: a -> FStar.DM4F.IntStoreExcFixed.int_store_exc a
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.DM4F.IntStoreExcFixed.int_store_exc" ]
[]
false
false
false
true
false
let return_is (a: Type) (x: a) : int_store_exc a =
fun store -> Some x, store
false
FStar.DM4F.IntStoreExcFixed.fst
FStar.DM4F.IntStoreExcFixed.iget
val iget: Prims.unit -> int_store_exc (heap)
val iget: Prims.unit -> int_store_exc (heap)
let iget () : int_store_exc (heap) = fun store -> Some store, store
{ "file_name": "examples/dm4free/FStar.DM4F.IntStoreExcFixed.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 67, "end_line": 30, "start_col": 0, "start_line": 30 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.DM4F.IntStoreExcFixed open FStar.DM4F.Heap.IntStoreFixed (* TODO : Try to use [either a exn] instead of [option] *) type int_store_exc (a:Type) = heap -> M (option a * heap) let return_is (a:Type) (x:a) : int_store_exc a = fun store -> Some x, store let bind_is (a b : Type) (x:int_store_exc a) (f: a -> int_store_exc b) : int_store_exc b = fun store -> let (z, store') = x store in match z with | None -> None, store' | Some xa -> f xa store'
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntStoreExcFixed.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.DM4F.IntStoreExcFixed.int_store_exc FStar.DM4F.Heap.IntStoreFixed.heap
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.tuple2", "FStar.DM4F.IntStoreExcFixed.int_store_exc" ]
[]
false
false
false
true
false
let iget () : int_store_exc (heap) =
fun store -> Some store, store
false
FStar.DM4F.IntStoreExcFixed.fst
FStar.DM4F.IntStoreExcFixed.raise_impl
val raise_impl: Prims.unit -> int_store_exc False
val raise_impl: Prims.unit -> int_store_exc False
let raise_impl () : int_store_exc False = fun store -> None, store
{ "file_name": "examples/dm4free/FStar.DM4F.IntStoreExcFixed.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 35, "start_col": 0, "start_line": 35 }
(* 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.DM4F.IntStoreExcFixed open FStar.DM4F.Heap.IntStoreFixed (* TODO : Try to use [either a exn] instead of [option] *) type int_store_exc (a:Type) = heap -> M (option a * heap) let return_is (a:Type) (x:a) : int_store_exc a = fun store -> Some x, store let bind_is (a b : Type) (x:int_store_exc a) (f: a -> int_store_exc b) : int_store_exc b = fun store -> let (z, store') = x store in match z with | None -> None, store' | Some xa -> f xa store' let iget () : int_store_exc (heap) = fun store -> Some store, store let iput s : int_store_exc unit = fun _ -> Some (), s (* DM4F does not handle polymorphic types yet so we go around this limitation *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntStoreExcFixed.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.DM4F.IntStoreExcFixed.int_store_exc Prims.l_False
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "Prims.l_False", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2", "FStar.DM4F.IntStoreExcFixed.int_store_exc" ]
[]
false
false
false
true
false
let raise_impl () : int_store_exc False =
fun store -> None, store
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT16BE
val validate____UINT16BE : validator parse____UINT16BE
val validate____UINT16BE : validator parse____UINT16BE
let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 75, "end_line": 1515, "start_col": 0, "start_line": 1511 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT16BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT16BE", "EverParse3d.Prelude.___UINT16BE", "EverParse3d.Prelude.parse____UINT16BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT16BE:validator parse____UINT16BE =
validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT8BE
val read____UINT8BE : leaf_reader parse____UINT8BE
val read____UINT8BE : leaf_reader parse____UINT8BE
let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 48, "end_line": 1508, "start_col": 0, "start_line": 1506 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT8BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Int.read_u8", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT8BE", "EverParse3d.Prelude.___UINT8BE", "EverParse3d.Prelude.parse____UINT8BE" ]
[]
false
false
false
false
false
let read____UINT8BE:leaf_reader parse____UINT8BE =
lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_nlist_constant_size_mod_ko
val validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0)) (ensures (fun _ -> True))
val validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv disj l: _) : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0)) (ensures (fun _ -> True))
let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos )
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 1253, "start_col": 0, "start_line": 1219 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> disj: EverParse3d.Actions.Base.disjointness_pre -> l: EverParse3d.Actions.Base.eloc -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv disj l true)
Prims.Pure
[]
[]
[ "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_list_size_not_multiple", "Prims.unit", "FStar.Classical.move_requires", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "EverParse3d.Prelude.nlist", "LowParse.Spec.Base.consumed_length", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Base.parse", "EverParse3d.Prelude.parse_nlist", "Prims.l_False", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.UInt32.v", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "FStar.Math.Lemmas.cancel_mul_mod", "FStar.List.Tot.Base.length", "Prims.op_Multiply", "FStar.Pervasives.Native.option", "LowParse.Spec.List.list_length_constant_size_parser_correct", "FStar.Seq.Base.seq", "FStar.UInt8.t", "FStar.Seq.Base.slice", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind_nlist", "Prims.l_and", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "Prims.op_disEquality", "Prims.l_True" ]
[]
false
false
false
false
false
let validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) #t (p: parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0)) (ensures (fun _ -> True)) =
(fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let h = FStar.HyperStack.ST.get () in [@@ inline_let ]let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq'; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == (FStar.List.Tot.length l) `Prims.op_Multiply` k.LP.parser_kind_low); FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low; assert (U32.v n % k.LP.parser_kind_low == 0) in [@@ inline_let ]let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos)
false
FStar.DM4F.IntStoreExcFixed.fst
FStar.DM4F.IntStoreExcFixed.bind_is
val bind_is (a b: Type) (x: int_store_exc a) (f: (a -> int_store_exc b)) : int_store_exc b
val bind_is (a b: Type) (x: int_store_exc a) (f: (a -> int_store_exc b)) : int_store_exc b
let bind_is (a b : Type) (x:int_store_exc a) (f: a -> int_store_exc b) : int_store_exc b = fun store -> let (z, store') = x store in match z with | None -> None, store' | Some xa -> f xa store'
{ "file_name": "examples/dm4free/FStar.DM4F.IntStoreExcFixed.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 28, "end_line": 28, "start_col": 0, "start_line": 23 }
(* 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.DM4F.IntStoreExcFixed open FStar.DM4F.Heap.IntStoreFixed (* TODO : Try to use [either a exn] instead of [option] *) type int_store_exc (a:Type) = heap -> M (option a * heap)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.DM4F.IntStoreFixed.fst.checked", "FStar.DM4F.Heap.IntStoreFixed.fsti.checked" ], "interface_file": false, "source_file": "FStar.DM4F.IntStoreExcFixed.fst" }
[ { "abbrev": false, "full_module": "FStar.DM4F.Heap.IntStoreFixed", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.DM4F", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Type -> b: Type -> x: FStar.DM4F.IntStoreExcFixed.int_store_exc a -> f: (_: a -> FStar.DM4F.IntStoreExcFixed.int_store_exc b) -> FStar.DM4F.IntStoreExcFixed.int_store_exc b
Prims.Tot
[ "total" ]
[]
[ "FStar.DM4F.IntStoreExcFixed.int_store_exc", "FStar.DM4F.Heap.IntStoreFixed.heap", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.tuple2" ]
[]
false
false
false
true
false
let bind_is (a b: Type) (x: int_store_exc a) (f: (a -> int_store_exc b)) : int_store_exc b =
fun store -> let z, store' = x store in match z with | None -> None, store' | Some xa -> f xa store'
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT32BE
val read____UINT32BE : leaf_reader parse____UINT32BE
val read____UINT32BE : leaf_reader parse____UINT32BE
let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 49, "end_line": 1532, "start_col": 0, "start_line": 1530 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT32BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u32_kind", "FStar.UInt32.t", "LowParse.Spec.Int.parse_u32", "LowParse.Low.Int.read_u32", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT32BE", "EverParse3d.Prelude.___UINT32BE", "EverParse3d.Prelude.parse____UINT32BE" ]
[]
false
false
false
false
false
let read____UINT32BE:leaf_reader parse____UINT32BE =
lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_chan_inv_eqT
val intro_chan_inv_eqT (#p: _) (c: chan_t p) (vs vr: chan_val) : Steel unit (((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True)
val intro_chan_inv_eqT (#p: _) (c: chan_t p) (vs vr: chan_val) : Steel unit (((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True)
let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 122, "start_col": 0, "start_line": 114 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Steel.Channel.Simplex.chan_t p -> vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.intro_chan_inv_auxT", "Prims.unit", "Steel.Channel.Simplex.intro_chan_inv_cond_eqT", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.eq2", "Prims.l_True" ]
[]
false
true
false
false
false
let intro_chan_inv_eqT #p (c: chan_t p) (vs: chan_val) (vr: chan_val) : Steel unit (((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) =
intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_ite
val validate_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk) (e:bool) (#[@@@erasable] a:squash e -> Type) (#[@@@erasable] b:squash (not e) -> Type) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#ar1:_) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#ar2:_) ([@@@erasable] p1:squash e -> parser k (a())) (v1:(squash e -> validate_with_action_t (p1()) inv1 disj1 l1 ar1)) ([@@@erasable] p2:squash (not e) -> parser k (b())) (v2:(squash (not e) -> validate_with_action_t (p2()) inv2 disj2 l2 ar2)) : validate_with_action_t (parse_ite e p1 p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
val validate_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk) (e:bool) (#[@@@erasable] a:squash e -> Type) (#[@@@erasable] b:squash (not e) -> Type) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#ar1:_) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#ar2:_) ([@@@erasable] p1:squash e -> parser k (a())) (v1:(squash e -> validate_with_action_t (p1()) inv1 disj1 l1 ar1)) ([@@@erasable] p2:squash (not e) -> parser k (b())) (v2:(squash (not e) -> validate_with_action_t (p2()) inv2 disj2 l2 ar2)) : validate_with_action_t (parse_ite e p1 p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 85, "end_line": 877, "start_col": 0, "start_line": 872 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
e: Prims.bool -> p1: (_: Prims.squash e -> EverParse3d.Prelude.parser k (a ())) -> v1: (_: Prims.squash e -> EverParse3d.Actions.Base.validate_with_action_t (p1 ()) inv1 disj1 l1 ar1) -> p2: (_: Prims.squash (Prims.op_Negation e) -> EverParse3d.Prelude.parser k (b ())) -> v2: (_: Prims.squash (Prims.op_Negation e) -> EverParse3d.Actions.Base.validate_with_action_t (p2 ()) inv2 disj2 l2 ar2) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_ite e p1 p2) (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.conj_disjointness disj1 disj2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "Prims.squash", "Prims.b2t", "Prims.op_Negation", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.Actions.Base.validate_drop", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let validate_ite e p1 v1 p2 v2 =
fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_all_zeros
val validate_all_zeros : validate_with_action_t parse_all_zeros true_inv disjointness_trivial eloc_none false
val validate_all_zeros : validate_with_action_t parse_all_zeros true_inv disjointness_trivial eloc_none false
let validate_all_zeros = validate_list (validate_filter "parse_zeros" validate____UINT8 read____UINT8 is_zero "check if zero" "")
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 106, "end_line": 1736, "start_col": 0, "start_line": 1735 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo unfold let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end inline_for_extraction let validate_list_up_to_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (v: validator p) (r: leaf_reader p) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (h0: HS.mem) (bres: B.pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false )) (ensures (fun h stop h' -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false /\ validate_list_up_to_inv p terminator prf ctxt sl h0 bres h' stop )) = let h = HST.get () in LUT.parse_list_up_to_eq (cond_string_up_to terminator) p prf (I.get_remaining sl h); let position = !* bres in let result = v ctxt error_handler_fn sl sl_len position in B.upd bres 0ul result; if LPE.is_error result then begin true end else begin let value = r sl position in cond_string_up_to terminator value end inline_for_extraction noextract let validate_list_up_to (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) : validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv disjointness_trivial eloc_none false = fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres) ; let result = B.index bres 0ul in HST.pop_frame (); result let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) = LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _ let validate_all_bytes = fun _ _ input input_length start_position -> I.empty input input_length start_position
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validate_with_action_t EverParse3d.Prelude.parse_all_zeros EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_list", "EverParse3d.Kinds.filter_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT8", "EverParse3d.Prelude.refine", "EverParse3d.Prelude.___UINT8", "EverParse3d.Prelude.is_zero", "EverParse3d.Prelude.parse_filter", "EverParse3d.Prelude.parse____UINT8", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_filter", "EverParse3d.Actions.Base.validate____UINT8", "EverParse3d.Actions.Base.read____UINT8" ]
[]
false
false
false
false
false
let validate_all_zeros =
validate_list (validate_filter "parse_zeros" validate____UINT8 read____UINT8 is_zero "check if zero" "")
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT16
val validate____UINT16 : validator parse____UINT16
val validate____UINT16 : validator parse____UINT16
let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 73, "end_line": 1551, "start_col": 0, "start_line": 1547 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT16
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT16", "EverParse3d.Prelude.___UINT16", "EverParse3d.Prelude.parse____UINT16", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT16:validator parse____UINT16 =
validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT64BE
val read____UINT64BE : leaf_reader parse____UINT64BE
val read____UINT64BE : leaf_reader parse____UINT64BE
let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 49, "end_line": 1544, "start_col": 0, "start_line": 1542 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT64BE
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u64_kind", "FStar.UInt64.t", "LowParse.Spec.Int.parse_u64", "LowParse.Low.Int.read_u64", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT64BE", "EverParse3d.Prelude.___UINT64BE", "EverParse3d.Prelude.parse____UINT64BE" ]
[]
false
false
false
false
false
let read____UINT64BE:leaf_reader parse____UINT64BE =
lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT16
val read____UINT16 : leaf_reader parse____UINT16
val read____UINT16 : leaf_reader parse____UINT16
let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 59, "end_line": 1556, "start_col": 0, "start_line": 1554 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT16
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u16_kind", "FStar.UInt16.t", "LowParse.Spec.BoundedInt.parse_u16_le", "LowParse.Low.BoundedInt.read_u16_le", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT16", "EverParse3d.Prelude.___UINT16", "EverParse3d.Prelude.parse____UINT16" ]
[]
false
false
false
false
false
let read____UINT16:leaf_reader parse____UINT16 =
lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.synth_list_up_to'
val synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond)
val synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond)
let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy)
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 18, "end_line": 238, "start_col": 0, "start_line": 232 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> fuel: Prims.nat -> xy: LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel -> LowParse.Spec.ListUpTo.parse_list_up_to_t cond
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.nat", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "LowParse.Spec.ListUpTo.llist", "FStar.Pervasives.Native.snd", "LowParse.Spec.ListUpTo.parse_list_up_to_t" ]
[]
false
false
false
false
false
let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) =
(fst xy, snd xy)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT32
val validate____UINT32 : validator parse____UINT32
val validate____UINT32 : validator parse____UINT32
let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 73, "end_line": 1563, "start_col": 0, "start_line": 1559 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT32
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT32", "EverParse3d.Prelude.___UINT32", "EverParse3d.Prelude.parse____UINT32", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT32:validator parse____UINT32 =
validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT32
val read____UINT32 : leaf_reader parse____UINT32
val read____UINT32 : leaf_reader parse____UINT32
let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 59, "end_line": 1568, "start_col": 0, "start_line": 1566 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT32
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u32_kind", "FStar.UInt32.t", "LowParse.Spec.BoundedInt.parse_u32_le", "LowParse.Low.BoundedInt.read_u32_le", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT32", "EverParse3d.Prelude.___UINT32", "EverParse3d.Prelude.parse____UINT32" ]
[]
false
false
false
false
false
let read____UINT32:leaf_reader parse____UINT32 =
lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate____UINT64
val validate____UINT64 : validator parse____UINT64
val validate____UINT64 : validator parse____UINT64
let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 73, "end_line": 1575, "start_col": 0, "start_line": 1571 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT64
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT64", "EverParse3d.Prelude.___UINT64", "EverParse3d.Prelude.parse____UINT64", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
false
false
false
false
false
let validate____UINT64:validator parse____UINT64 =
validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _)
false
Steel.SpinLock.fst
Steel.SpinLock.acquire
val acquire (#p:vprop) (l:lock p) : SteelT unit emp (fun _ -> p)
val acquire (#p:vprop) (l:lock p) : SteelT unit emp (fun _ -> p)
let rec acquire #p l = let r:ref bool = l.r in let i: inv (lockinv p r) = l.i in let b = with_invariant i (fun _ -> acquire_core r i) in if b then ( rewrite_slprop (if b then p else emp) p (fun _ -> ()); noop () ) else ( rewrite_slprop (if b then p else emp) emp (fun _ -> ()); acquire l )
{ "file_name": "lib/steel/Steel.SpinLock.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 3, "end_line": 89, "start_col": 0, "start_line": 79 }
(* 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.SpinLock open FStar.Ghost open Steel.Effect.Atomic open Steel.Effect open Steel.Reference open Steel.FractionalPermission #set-options "--ide_id_info_off --fuel 0 --ifuel 0" let available = false let locked = true let lockinv (p:vprop) (r:ref bool) : vprop = h_exists (fun b -> pts_to r full_perm b `star` (if b then emp else p)) noeq type lock (p:vprop) = | Lock: r: ref bool -> i: inv (lockinv p r) -> lock p val intro_lockinv_available (#uses:inames) (p:vprop) (r:ref bool) : SteelGhostT unit uses (pts_to r full_perm available `star` p) (fun _ -> lockinv p r) val intro_lockinv_locked (#uses:inames) (p:vprop) (r:ref bool) : SteelGhostT unit uses (pts_to r full_perm locked) (fun _ -> lockinv p r) let intro_lockinv_available #uses p r = intro_exists false (fun (b: bool) -> pts_to r full_perm b `star` (if b then emp else p) ) let intro_lockinv_locked #uses p r = intro_exists true (fun b -> pts_to r full_perm b `star` (if b then emp else p)) let new_lock (p:vprop) : SteelT (lock p) p (fun _ -> emp) = let r = alloc_pt available in intro_lockinv_available p r; let i:inv (lockinv p r) = new_invariant (lockinv p r) in return (Lock r i) val acquire_core (#p:vprop) (#u:inames) (r:ref bool) (i:inv (lockinv p r)) : SteelAtomicT bool u (lockinv p r `star` emp) (fun b -> lockinv p r `star` (if b then p else emp)) let acquire_core #p #u r i = let ghost = witness_exists () in let res = cas_pt_bool r ghost available locked in (* Not sure we can avoid calling an SMT here. Better force the manual call? *) rewrite_slprop (if (Ghost.reveal ghost) then emp else p) (if res then p else emp) (fun _ -> ()); rewrite_slprop (if res then pts_to r full_perm (Ghost.hide locked) else pts_to r full_perm ghost) (pts_to r full_perm locked) (fun _ -> ()); intro_lockinv_locked p r; return res
{ "checked_file": "/", "dependencies": [ "Steel.Reference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "prims.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.SpinLock.fst" }
[ { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.Reference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "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 } ]
{ "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": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: Steel.SpinLock.lock p -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Effect.Common.vprop", "Steel.SpinLock.lock", "Steel.Effect.Atomic.noop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "Prims.bool", "Steel.Effect.Common.emp", "Steel.Memory.mem", "Steel.SpinLock.acquire", "Steel.Effect.Atomic.with_invariant", "Steel.Effect.Common.Observable", "Steel.SpinLock.lockinv", "Steel.SpinLock.acquire_core", "Steel.Effect.Common.add_inv", "Steel.Effect.Common.inv", "Steel.SpinLock.__proj__Lock__item__i", "Steel.Reference.ref", "Steel.SpinLock.__proj__Lock__item__r" ]
[ "recursion" ]
false
true
false
false
false
let rec acquire #p l =
let r:ref bool = l.r in let i:inv (lockinv p r) = l.i in let b = with_invariant i (fun _ -> acquire_core r i) in if b then (rewrite_slprop (if b then p else emp) p (fun _ -> ()); noop ()) else (rewrite_slprop (if b then p else emp) emp (fun _ -> ()); acquire l)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list_body
val validate_list_body (#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res))
val validate_list_body (#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res))
let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 966, "start_col": 0, "start_line": 935 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validate_with_action_t' p inv disj l ar -> g0: FStar.Ghost.erased FStar.Monotonic.HyperStack.mem -> g1: FStar.Ghost.erased FStar.Monotonic.HyperStack.mem -> ctxt: EverParse3d.Actions.Base.app_ctxt -> error_handler_fn: EverParse3d.Actions.Base.error_handler -> sl: EverParse3d.Actions.Base.input_buffer_t -> sl_len: EverParse3d.InputStream.Base.tlen sl -> bres: LowStar.Buffer.pointer FStar.UInt64.t -> FStar.HyperStack.ST.Stack Prims.bool
FStar.HyperStack.ST.Stack
[]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t'", "FStar.Ghost.erased", "FStar.Monotonic.HyperStack.mem", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "LowStar.Buffer.pointer", "FStar.UInt64.t", "EverParse3d.ErrorCode.is_error", "Prims.unit", "LowStar.Monotonic.Buffer.upd", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "EverParse3d.Actions.Base.validate_drop", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Ghost.reveal", "FStar.HyperStack.ST.get", "Prims.op_Negation", "EverParse3d.InputStream.Base.has", "FStar.UInt64.__uint_to_t", "LowStar.BufferOps.op_Bang_Star", "LowParse.Spec.List.parse_list_eq", "EverParse3d.InputStream.Base.get_remaining", "EverParse3d.Actions.Base.validate_list_inv", "Prims.l_and" ]
[]
false
true
false
false
false
let validate_list_body (#[EverParse3d.Util.solve_from_ctx ()] _extra_t: I.extra_t #input_buffer_t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0: Ghost.erased HS.mem) (g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res)) =
let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !*bres in if not (I.has sl sl_len position 1uL) then true else let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_unit
val validate_unit : validator parse_unit
val validate_unit : validator parse_unit
let validate_unit = fun _ _ input _ start_position -> start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 50, "end_line": 1584, "start_col": 0, "start_line": 1583 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse_unit
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let validate_unit =
fun _ _ input _ start_position -> start_position
false
Steel.ST.Array.Util.fst
Steel.ST.Array.Util.forall_body
val forall_body: #a: Type0 -> n: US.t -> arr: A.array a -> p: (a -> bool) -> r: R.ref US.t -> perm: perm -> s: G.erased (Seq.seq a) -> squash (Seq.length s == US.v n) -> unit -> STT unit (forall_inv n arr p r perm s () true) (fun _ -> exists_ (forall_inv n arr p r perm s ()))
val forall_body: #a: Type0 -> n: US.t -> arr: A.array a -> p: (a -> bool) -> r: R.ref US.t -> perm: perm -> s: G.erased (Seq.seq a) -> squash (Seq.length s == US.v n) -> unit -> STT unit (forall_inv n arr p r perm s () true) (fun _ -> exists_ (forall_inv n arr p r perm s ()))
let forall_body (#a:Type0) (n:US.t) (arr:A.array a) (p:a -> bool) (r:R.ref US.t) (perm:perm) (s:G.erased (Seq.seq a)) (_:squash (Seq.length s == US.v n)) : unit -> STT unit (forall_inv n arr p r perm s () true) (fun _ -> exists_ (forall_inv n arr p r perm s ())) = fun _ -> let _ = elim_exists () in elim_pure _; elim_pure _; //atomic increment? let i = R.read r in R.write r (US.add i 1sz); intro_pure (forall_pure_inv n p s () (US.add i 1sz)); intro_pure (forall_pure_inv_b n p s () (US.add i 1sz) ((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))); intro_exists (US.add i 1sz) (forall_pred n arr p r perm s () ((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))); intro_exists ((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))) (forall_inv n arr p r perm s ())
{ "file_name": "lib/steel/Steel.ST.Array.Util.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 38, "end_line": 225, "start_col": 0, "start_line": 193 }
(* Copyright 2021 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.ST.Array.Util module G = FStar.Ghost module US = FStar.SizeT module R = Steel.ST.Reference module A = Steel.ST.Array module Loops = Steel.ST.Loops open Steel.FractionalPermission open Steel.ST.Effect open Steel.ST.Util /// Implementation of array_literal using a for loop let array_literal_inv_pure (#a:Type0) (n:US.t) (f:(i:US.t{US.v i < US.v n} -> a)) (i:Loops.nat_at_most n) (s:Seq.seq a) : prop = forall (j:nat). (j < i /\ j < Seq.length s) ==> Seq.index s j == f (US.uint_to_t j) [@@ __reduce__] let array_literal_inv (#a:Type0) (n:US.t) (arr:A.array a) (f:(i:US.t{US.v i < US.v n} -> a)) (i:Loops.nat_at_most n) : Seq.seq a -> vprop = fun s -> A.pts_to arr full_perm s `star` pure (array_literal_inv_pure n f i s) inline_for_extraction let array_literal_loop_body (#a:Type0) (n:US.t) (arr:A.array a{A.length arr == US.v n}) (f:(i:US.t{US.v i < US.v n} -> a)) : i:Loops.u32_between 0sz n -> STT unit (exists_ (array_literal_inv n arr f (US.v i))) (fun _ -> exists_ (array_literal_inv n arr f (US.v i + 1))) = fun i -> let s = elim_exists () in (); A.pts_to_length arr s; elim_pure (array_literal_inv_pure n f (US.v i) s); A.write arr i (f i); intro_pure (array_literal_inv_pure n f (US.v i + 1) (Seq.upd s (US.v i) (f i))); intro_exists (Seq.upd s (US.v i) (f i)) (array_literal_inv n arr f (US.v i + 1)) let array_literal #a n f = let arr = A.alloc (f 0sz) n in intro_pure (array_literal_inv_pure n f 1 (Seq.create (US.v n) (f 0sz))); intro_exists (Seq.create (US.v n) (f 0sz)) (array_literal_inv n arr f 1); Loops.for_loop 1sz n (fun i -> exists_ (array_literal_inv n arr f i)) (array_literal_loop_body n arr f); let s = elim_exists () in A.pts_to_length arr s; elim_pure (array_literal_inv_pure n f (US.v n) s); assert (Seq.equal s (Seq.init (US.v n) (fun i -> f (US.uint_to_t i)))); rewrite (A.pts_to arr full_perm s) _; return arr /// Implementation of for_all using a while loop let forall_pure_inv (#a:Type0) (n:US.t) (p:a -> bool) (s:Seq.seq a) (_:squash (Seq.length s == US.v n)) (i:US.t) : prop = i `US.lte` n /\ (forall (j:nat). j < US.v i ==> p (Seq.index s j)) let forall_pure_inv_b (#a:Type0) (n:US.t) (p:a -> bool) (s:Seq.seq a) (_:squash (Seq.length s == US.v n)) (i:US.t) (b:bool) : prop = b == (i `US.lt` n && p (Seq.index s (US.v i))) [@@ __reduce__] let forall_pred (#a:Type0) (n:US.t) (arr:A.array a) (p:a -> bool) (r:R.ref US.t) (perm:perm) (s:Seq.seq a) (_:squash (Seq.length s == US.v n)) (b:bool) : US.t -> vprop = fun i -> A.pts_to arr perm s `star` R.pts_to r full_perm i `star` pure (forall_pure_inv n p s () i) `star` pure (forall_pure_inv_b n p s () i b) [@@ __reduce__] let forall_inv (#a:Type0) (n:US.t) (arr:A.array a) (p:a -> bool) (r:R.ref US.t) (perm:perm) (s:Seq.seq a) (_:squash (Seq.length s == US.v n)) : bool -> vprop = fun b -> exists_ (forall_pred n arr p r perm s () b) inline_for_extraction let forall_cond (#a:Type0) (n:US.t) (arr:A.array a) (p:a -> bool) (r:R.ref US.t) (perm:perm) (s:G.erased (Seq.seq a)) (_:squash (Seq.length s == US.v n)) : unit -> STT bool (exists_ (forall_inv n arr p r perm s ())) (forall_inv n arr p r perm s ()) = fun _ -> let _ = elim_exists () in let _ = elim_exists () in elim_pure _; elim_pure _; let i = R.read r in let b = i = n in let res = if b then return false else let elt = A.read arr i in return (p elt) in intro_pure (forall_pure_inv n p s () i); intro_pure (forall_pure_inv_b n p s () i res); intro_exists i (forall_pred n arr p r perm s () res); return res
{ "checked_file": "/", "dependencies": [ "Steel.ST.Util.fsti.checked", "Steel.ST.Reference.fsti.checked", "Steel.ST.Loops.fsti.checked", "Steel.ST.Effect.fsti.checked", "Steel.ST.Array.fsti.checked", "Steel.FractionalPermission.fst.checked", "prims.fst.checked", "FStar.SizeT.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked" ], "interface_file": true, "source_file": "Steel.ST.Array.Util.fst" }
[ { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": true, "full_module": "Steel.ST.Loops", "short_module": "Loops" }, { "abbrev": true, "full_module": "Steel.ST.Array", "short_module": "A" }, { "abbrev": true, "full_module": "Steel.ST.Reference", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "Steel.ST.Util", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": true, "full_module": "Steel.ST.Array", "short_module": "A" }, { "abbrev": true, "full_module": "FStar.SizeT", "short_module": "US" }, { "abbrev": true, "full_module": "FStar.Ghost", "short_module": "G" }, { "abbrev": false, "full_module": "Steel.ST.Array", "short_module": null }, { "abbrev": false, "full_module": "Steel.ST.Array", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.SizeT.t -> arr: Steel.ST.Array.array a -> p: (_: a -> Prims.bool) -> r: Steel.ST.Reference.ref FStar.SizeT.t -> perm: Steel.FractionalPermission.perm -> s: FStar.Ghost.erased (FStar.Seq.Base.seq a) -> _: Prims.squash (FStar.Seq.Base.length (FStar.Ghost.reveal s) == FStar.SizeT.v n) -> _: Prims.unit -> Steel.ST.Effect.STT Prims.unit
Steel.ST.Effect.STT
[]
[]
[ "FStar.SizeT.t", "Steel.ST.Array.array", "Prims.bool", "Steel.ST.Reference.ref", "Steel.FractionalPermission.perm", "FStar.Ghost.erased", "FStar.Seq.Base.seq", "Prims.squash", "Prims.eq2", "Prims.nat", "FStar.Seq.Base.length", "FStar.Ghost.reveal", "FStar.SizeT.v", "Prims.unit", "Steel.ST.Util.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.op_AmpAmp", "FStar.SizeT.lt", "FStar.SizeT.add", "FStar.SizeT.__uint_to_t", "FStar.Seq.Base.index", "Steel.ST.Array.Util.forall_inv", "Steel.ST.Array.Util.forall_pred", "Steel.ST.Util.intro_pure", "Steel.ST.Array.Util.forall_pure_inv_b", "Steel.ST.Array.Util.forall_pure_inv", "Steel.ST.Reference.write", "Steel.ST.Reference.read", "Steel.FractionalPermission.full_perm", "Steel.ST.Util.elim_pure", "Steel.ST.Util.elim_exists", "Steel.Effect.Common.VStar", "Steel.ST.Array.pts_to", "Steel.ST.Reference.pts_to", "Steel.ST.Util.pure", "Steel.Effect.Common.vprop", "Steel.ST.Util.exists_" ]
[]
false
true
false
false
false
let forall_body (#a: Type0) (n: US.t) (arr: A.array a) (p: (a -> bool)) (r: R.ref US.t) (perm: perm) (s: G.erased (Seq.seq a)) (_: squash (Seq.length s == US.v n)) : unit -> STT unit (forall_inv n arr p r perm s () true) (fun _ -> exists_ (forall_inv n arr p r perm s ())) =
fun _ -> let _ = elim_exists () in elim_pure _; elim_pure _; let i = R.read r in R.write r (US.add i 1sz); intro_pure (forall_pure_inv n p s () (US.add i 1sz)); intro_pure (forall_pure_inv_b n p s () (US.add i 1sz) ((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))); intro_exists (US.add i 1sz) (forall_pred n arr p r perm s () ((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz))))); intro_exists ((US.add i 1sz) `US.lt` n && p (Seq.index s (US.v (US.add i 1sz)))) (forall_inv n arr p r perm s ())
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.external_action
val external_action (l: eloc) : Tot Type0
val external_action (l: eloc) : Tot Type0
let external_action l = unit -> Stack unit (fun _ -> True) (fun h0 _ h1 -> B.modifies l h0 h1)
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 72, "end_line": 1839, "start_col": 0, "start_line": 1838 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo unfold let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end inline_for_extraction let validate_list_up_to_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (v: validator p) (r: leaf_reader p) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (h0: HS.mem) (bres: B.pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false )) (ensures (fun h stop h' -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false /\ validate_list_up_to_inv p terminator prf ctxt sl h0 bres h' stop )) = let h = HST.get () in LUT.parse_list_up_to_eq (cond_string_up_to terminator) p prf (I.get_remaining sl h); let position = !* bres in let result = v ctxt error_handler_fn sl sl_len position in B.upd bres 0ul result; if LPE.is_error result then begin true end else begin let value = r sl position in cond_string_up_to terminator value end inline_for_extraction noextract let validate_list_up_to (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) : validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv disjointness_trivial eloc_none false = fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres) ; let result = B.index bres 0ul in HST.pop_frame (); result let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) = LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _ let validate_all_bytes = fun _ _ input input_length start_position -> I.empty input input_length start_position let validate_all_zeros = validate_list (validate_filter "parse_zeros" validate____UINT8 read____UINT8 is_zero "check if zero" "") //////////////////////////////////////////////////////////////////////////////// noextract inline_for_extraction let action_return (#a:Type) (x:a) = fun _ _ _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) (#invf:slice_inv) #disjf (#lf:eloc) #bf (#a:Type) (f: action invf disjf lf bf a) (#invg:slice_inv) #disjg (#lg:eloc) #bg (#b:Type) (g: (a -> action invg disjg lg bg b)) = fun ctxt error_handler_fn input input_length pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt error_handler_fn input input_length pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt error_handler_fn input input_length pos posf noextract inline_for_extraction let action_seq (#invf:slice_inv) #disjf (#lf:eloc) #bf (#a:Type) (f: action invf disjf lf bf a) (#invg:slice_inv) #disjg (#lg:eloc) #bg (#b:Type) (g: action invg disjg lg bg b) = fun ctxt error_handler_fn input input_length pos posf -> let h0 = HST.get () in let _ = f ctxt error_handler_fn input input_length pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt error_handler_fn input input_length pos posf noextract inline_for_extraction let action_ite (#invf:slice_inv) #disjf (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action invf disjf lf bf a) (#invg:slice_inv) #disjg (#lg:eloc) #bg (else_: squash (not guard) -> action invg disjg lg bg a) = fun ctxt error_handler_fn input input_length pos posf -> if guard then then_ () ctxt error_handler_fn input input_length pos posf else else_ () ctxt error_handler_fn input input_length pos posf noextract inline_for_extraction let action_abort = fun _ _ _ _ _ _ -> false noextract inline_for_extraction let action_field_pos_64 = fun _ _ _ _ pos _ -> pos (* FIXME: this is now unsound in general (only valid for flat buffer) noextract inline_for_extraction let action_field_ptr #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (u:unit) : action p true_inv eloc_none true LPL.puint8 = fun input startPosition _ -> let open LowParse.Slice in LPL.offset input (LPL.uint64_to_uint32 startPosition) *) module T = FStar.Tactics let ptr_inv_elim (x:B.pointer 'a) : Lemma (ensures forall h. ptr_inv x h ==> B.live h x) = introduce forall h. ptr_inv x h ==> B.live h x with assert (ptr_inv x h ==> B.live h x) by (T.norm [delta]) noextract inline_for_extraction let action_deref (#a:_) (x:B.pointer a) = fun _ _ _ _ _ _ -> ptr_inv_elim x; !*x noextract inline_for_extraction let action_assignment (#a:_) (x:B.pointer a) (v:a) = fun _ _ _ _ _ _ -> ptr_inv_elim x; x *= v noextract inline_for_extraction let action_weaken #inv #disj #l #b #a act #inv' #disj' #l' = act
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
l: EverParse3d.Actions.Base.eloc -> Type0
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.eloc", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "LowStar.Monotonic.Buffer.modifies", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc" ]
[]
false
false
false
true
true
let external_action l =
unit -> Stack unit (fun _ -> True) (fun h0 _ h1 -> B.modifies l h0 h1)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read_unit
val read_unit : leaf_reader (parse_ret ())
val read_unit : leaf_reader (parse_ret ())
let read_unit = fun input pos -> ()
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 21, "end_line": 1588, "start_col": 0, "start_line": 1587 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader (EverParse3d.Prelude.parse_ret ())
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "Prims.unit" ]
[]
false
false
false
false
false
let read_unit =
fun input pos -> ()
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_fldata_consumes_all
val validate_fldata_consumes_all (n: U32.t) (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar {k.LP.parser_kind_subkind == Some LP.ParserConsumesAll}) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false
val validate_fldata_consumes_all (n: U32.t) (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #disj #l #ar: _) (v: validate_with_action_t' p inv disj l ar {k.LP.parser_kind_subkind == Some LP.ParserConsumesAll}) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false
let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 1081, "start_col": 0, "start_line": 1053 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
n: FStar.UInt32.t -> v: EverParse3d.Actions.Base.validate_with_action_t' p inv disj l ar { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> EverParse3d.Actions.Base.validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (FStar.UInt32.v n)) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t'", "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.ParserConsumesAll", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "Prims.op_Negation", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_not_enough_data", "FStar.UInt64.t", "Prims.unit", "EverParse3d.InputStream.Base.is_prefix_of_prop", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.validate_drop", "Prims._assert", "FStar.Seq.Base.equal", "FStar.UInt8.t", "EverParse3d.InputStream.Base.get_remaining", "FStar.Seq.Base.slice", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "EverParse3d.InputStream.Base.__proj__Mkinput_stream_inst__item__tlen", "EverParse3d.InputStream.Base.truncate_len", "FStar.Int.Cast.uint32_to_uint64", "EverParse3d.InputStream.Base.truncate", "EverParse3d.InputStream.Base.has", "LowParse.Spec.FLData.parse_fldata_consumes_all_correct", "LowParse.Spec.FLData.parse_fldata_kind", "LowParse.Spec.FLData.parse_fldata" ]
[]
false
false
false
false
false
let validate_fldata_consumes_all (n: U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar {k.LP.parser_kind_subkind == Some LP.ParserConsumesAll}) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert ((I.get_remaining truncatedInput h2) `Seq.equal` (Seq.slice (I.get_remaining input h) 0 (U32.v n))); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.read____UINT64
val read____UINT64 : leaf_reader parse____UINT64
val read____UINT64 : leaf_reader parse____UINT64
let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 52, "end_line": 1580, "start_col": 0, "start_line": 1578 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT64
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u64_kind", "FStar.UInt64.t", "LowParse.Spec.Int.parse_u64_le", "LowParse.Low.Int.read_u64_le", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT64", "EverParse3d.Prelude.___UINT64", "EverParse3d.Prelude.parse____UINT64" ]
[]
false
false
false
false
false
let read____UINT64:leaf_reader parse____UINT64 =
lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_pair
val validate_pair (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#allow_reading1:bool) (v1:validate_with_action_t p1 inv1 disj1 l1 allow_reading1) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:Type) (#[@@@erasable] p2:parser k2 t2) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:validate_with_action_t p2 inv2 disj2 l2 allow_reading2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
val validate_pair (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] disj1:disjointness_pre) (#[@@@erasable] l1:eloc) (#allow_reading1:bool) (v1:validate_with_action_t p1 inv1 disj1 l1 allow_reading1) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:Type) (#[@@@erasable] p2:parser k2 t2) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:validate_with_action_t p2 inv2 disj2 l2 allow_reading2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 68, "end_line": 449, "start_col": 0, "start_line": 431 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name1: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 allow_reading1 -> v2: EverParse3d.Actions.Base.validate_with_action_t p2 inv2 disj2 l2 allow_reading2 -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_pair p1 p2) (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.conj_disjointness disj1 disj2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.weak_kind", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_error", "FStar.UInt64.t", "EverParse3d.Actions.Base.validate_drop", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Spec.Combinators.nondep_then_eq", "EverParse3d.InputStream.Base.get_remaining" ]
[]
false
false
false
false
false
let validate_pair (name1: string) #nz1 (#k1: parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1: parser k1 t1) (#inv1: _) (#disj1: _) (#l1: eloc) (#ar1: _) (v1: validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2: parser_kind nz2 wk2) #t2 (#p2: parser k2 t2) (#inv2: _) (#disj2: _) (#l2: eloc) (#ar2: _) (v2: validate_with_action_t p2 inv2 disj2 l2 ar2) =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@@ (rename_let ("positionAfter" ^ name1)) ]let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.synth_list_up_to_fuel
val synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1))
val synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1))
let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z)
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 15, "end_line": 43, "start_col": 0, "start_line": 32 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> fuel: Prims.nat -> xy: Prims.dtuple2 t (LowParse.Spec.ListUpTo.parse_list_up_to_payload_t cond fuel) -> LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond (fuel + 1)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.nat", "Prims.dtuple2", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.ListUpTo.llist", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "Prims.op_Addition", "Prims.Nil", "Prims.Cons", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t" ]
[]
false
false
false
false
false
let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) =
let (| x , yz |) = xy in if cond x then ([], x) else let y, z = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z)
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind
val parse_list_up_to_payload_kind (k: parser_kind) : Tot (k': parser_kind{k' `is_weaker_than` k})
val parse_list_up_to_payload_kind (k: parser_kind) : Tot (k': parser_kind{k' `is_weaker_than` k})
let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; }
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 1, "end_line": 60, "start_col": 0, "start_line": 55 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
k: LowParse.Spec.Base.parser_kind -> k': LowParse.Spec.Base.parser_kind{LowParse.Spec.Base.is_weaker_than k' k}
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.Mkparser_kind'", "FStar.Pervasives.Native.None", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.is_weaker_than" ]
[]
false
false
false
false
false
let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k': parser_kind{k' `is_weaker_than` k}) =
{ parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None }
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list_up_to_inv
val validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0
val validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0
let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 1653, "start_col": 0, "start_line": 1608 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: EverParse3d.Prelude.parser k t -> terminator: t -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond (EverParse3d.Prelude.cond_string_up_to terminator) p -> ctxt: EverParse3d.Actions.Base.app_ctxt -> sl: EverParse3d.Actions.Base.input_buffer_t -> h0: FStar.Monotonic.HyperStack.mem -> bres: LowStar.Buffer.pointer FStar.UInt64.t -> h: FStar.Monotonic.HyperStack.mem -> stop: Prims.bool -> Prims.GTot Type0
Prims.GTot
[ "sometrivial" ]
[]
[ "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "Prims.eqtype", "EverParse3d.Prelude.parser", "LowParse.Spec.ListUpTo.consumes_if_not_cond", "EverParse3d.Prelude.cond_string_up_to", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.input_buffer_t", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.pointer", "FStar.UInt64.t", "Prims.bool", "Prims.l_and", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "EverParse3d.InputStream.Base.live", "EverParse3d.InputStream.All.inst", "LowStar.Monotonic.Buffer.loc_disjoint", "EverParse3d.InputStream.Base.footprint", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc_none", "FStar.UInt8.t", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "LowStar.Monotonic.Buffer.modifies", "EverParse3d.InputStream.Base.perm_footprint", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "EverParse3d.ErrorCode.is_error", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "EverParse3d.ErrorCode.get_validator_error_pos", "EverParse3d.InputStream.Base.get_read", "Prims.l_imp", "Prims.op_disEquality", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "FStar.Pervasives.Native.uu___is_None", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "EverParse3d.Actions.Base.valid_consumed", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "FStar.Pervasives.Native.Mktuple2", "FStar.Pervasives.Native.option", "Prims.l_True", "Prims.op_Addition", "Prims.l_False", "Prims.logical", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Base.parser", "LowParse.Spec.ListUpTo.parse_list_up_to", "LowStar.Monotonic.Buffer.deref" ]
[]
false
false
false
false
true
let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 =
let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) ((B.loc_buffer bres) `B.loc_union` (app_loc ctxt loc_none)) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (((B.loc_buffer bres) `B.loc_union` (I.perm_footprint sl)) `B.loc_union` (app_loc ctxt loc_none)) h0 h /\ (let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` (Seq.slice s (Seq.length s - Seq.length s') (Seq.length s)) /\ (if LPE.is_error res then stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ (if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False)))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_filter_with_action
val validate_filter_with_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] disja:disjointness_pre) (#[@@@erasable] la:eloc) (a: t -> action inva disja la b bool) : validate_with_action_t #nz (p `parse_filter` f) (conj_inv inv inva) (conj_disjointness disj disja) (eloc_union l la) false
val validate_filter_with_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] disja:disjointness_pre) (#[@@@erasable] la:eloc) (a: t -> action inva disja la b bool) : validate_with_action_t #nz (p `parse_filter` f) (conj_inv inv inva) (conj_disjointness disj disja) (eloc_union l la) false
let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 810, "start_col": 0, "start_line": 779 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name: Prims.string -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l true -> r: EverParse3d.Actions.Base.leaf_reader p -> f: (_: t -> Prims.bool) -> cr: Prims.string -> cf: Prims.string -> a: (_: t -> EverParse3d.Actions.Base.action inva disja la b Prims.bool) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_filter p f) (EverParse3d.Actions.Base.conj_inv inv inva) (EverParse3d.Actions.Base.conj_disjointness disj disja) (EverParse3d.Actions.Base.eloc_union l la) false
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.action", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_error", "FStar.UInt64.t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_action_failed", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.ErrorCode.validator_error_constraint_failed", "LowStar.Comment.comment", "FStar.Pervasives.normalize_term", "Prims.op_Hat", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining" ]
[]
false
false
false
false
false
let validate_filter_with_action (name: string) #nz (#k: parser_kind nz _) (#t: _) (#p: parser k t) #inv #disj #l (v: validate_with_action_t p inv disj l true) (r: leaf_reader p) (f: (t -> bool)) (cr: string) (cf: string) (#b: bool) #inva #disja (#la: eloc) (a: (t -> action inva disja la b bool)) =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@@ (rename_let ("positionAfter" ^ name)) ]let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else (LowStar.Comment.comment cr; [@@ (rename_let ("" ^ name)) ]let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^ cf)); [@@ (rename_let (name ^ "ConstraintIsOk")) ]let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_unit_refinement
val validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f)
val validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f)
let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 78, "end_line": 1600, "start_col": 0, "start_line": 1591 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
f: (_: Prims.unit -> Prims.bool) -> cf: Prims.string -> EverParse3d.Actions.Base.validator (EverParse3d.Prelude.parse_filter EverParse3d.Prelude.parse_unit f)
Prims.Tot
[ "total" ]
[]
[ "Prims.unit", "Prims.bool", "Prims.string", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_constraint_failed", "FStar.UInt64.t", "LowStar.Comment.comment", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.Kinds.kind_unit", "EverParse3d.Prelude.parse_unit", "EverParse3d.InputStream.Base.get_remaining", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.validator", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.filter_kind", "EverParse3d.Prelude.refine", "EverParse3d.Prelude.parse_filter" ]
[]
false
false
false
false
false
let validate_unit_refinement (f: (unit -> bool)) (cf: string) : validator (parse_unit `parse_filter` f) =
fun _ _ input _ start_position -> [@@ inline_let ]let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_payload
val parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind{k.parser_kind_subkind <> Some ParserConsumesAll}) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x))
val parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind{k.parser_kind_subkind <> Some ParserConsumesAll}) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x))
let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 53, "end_line": 72, "start_col": 0, "start_line": 62 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> fuel: Prims.nat -> k: LowParse.Spec.Base.parser_kind { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> ptail: LowParse.Spec.Base.parser (LowParse.Spec.ListUpTo.parse_list_up_to_kind k) (LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel) -> x: t -> LowParse.Spec.Base.parser (LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind k) (LowParse.Spec.ListUpTo.parse_list_up_to_payload_t cond fuel x)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.nat", "LowParse.Spec.Base.parser_kind", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "LowParse.Spec.Base.parser", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.Base.weaken", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind", "LowParse.Spec.Combinators.parse_ret_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "LowParse.Spec.Combinators.parse_ret", "LowParse.Spec.ListUpTo.UP_UNIT" ]
[]
false
false
false
false
false
let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind{k.parser_kind_subkind <> Some ParserConsumesAll}) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) =
if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_fuel
val parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel)
val parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel)
let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1)
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 43, "end_line": 91, "start_col": 0, "start_line": 74 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> fuel: Prims.nat -> Prims.Tot (LowParse.Spec.Base.parser (LowParse.Spec.ListUpTo.parse_list_up_to_kind k) (LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel))
Prims.Tot
[ "total", "" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "Prims.nat", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.fail_parser", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.Combinators.and_then_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind", "Prims.dtuple2", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "Prims.op_Subtraction", "LowParse.Spec.Combinators.parse_dtuple2", "LowParse.Spec.Base.weaken", "LowParse.Spec.ListUpTo.parse_list_up_to_payload", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "LowParse.Spec.ListUpTo.synth_list_up_to_fuel" ]
[ "recursion" ]
false
false
false
false
false
let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) =
if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) `parse_synth` (synth_list_up_to_fuel cond (fuel - 1))
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to'_eq
val parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == (match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed)))
val parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == (match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed)))
let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed) )) = parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 268, "start_col": 0, "start_line": 251 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy) let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> fuel: Prims.nat -> b: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to' cond p fuel) b == (match LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel) b with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ xy consumed) -> FStar.Pervasives.Native.Some ((FStar.Pervasives.Native.fst xy, FStar.Pervasives.Native.snd xy), consumed)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "Prims.nat", "LowParse.Bytes.bytes", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "LowParse.Spec.ListUpTo.synth_list_up_to'", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.ListUpTo.parse_list_up_to'", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Mktuple2", "Prims.list", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "LowParse.Spec.ListUpTo.llist", "FStar.Pervasives.Native.snd", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == (match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed))) =
parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_fuel_indep
val parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel': nat{L.length (fst xy) < fuel'}) : Lemma (requires (parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed))) (ensures (parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed))) (decreases fuel)
val parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel': nat{L.length (fst xy) < fuel'}) : Lemma (requires (parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed))) (ensures (parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed))) (decreases fuel)
let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1)
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 79, "end_line": 161, "start_col": 0, "start_line": 133 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> fuel: Prims.nat -> b: LowParse.Bytes.bytes -> xy: LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel -> consumed: LowParse.Spec.Base.consumed_length b -> fuel': Prims.nat{FStar.List.Tot.Base.length (FStar.Pervasives.Native.fst xy) < fuel'} -> FStar.Pervasives.Lemma (requires LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel) b == FStar.Pervasives.Native.Some (xy, consumed)) (ensures LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel') b == FStar.Pervasives.Native.Some ((FStar.Pervasives.Native.fst xy, FStar.Pervasives.Native.snd xy), consumed)) (decreases fuel)
FStar.Pervasives.Lemma
[ "lemma", "" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "Prims.nat", "LowParse.Bytes.bytes", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.Base.consumed_length", "Prims.op_LessThan", "FStar.List.Tot.Base.length", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "LowParse.Spec.ListUpTo.llist", "Prims.op_Subtraction", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_indep", "Prims.unit", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.parse", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_eq", "Prims._assert", "Prims.op_GreaterThan", "Prims.eq2", "FStar.Pervasives.Native.Mktuple2", "Prims.squash", "FStar.Pervasives.Native.snd", "Prims.Nil", "FStar.Pervasives.pattern" ]
[ "recursion" ]
false
false
true
false
false
let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel': nat{L.length (fst xy) < fuel'}) : Lemma (requires (parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed))) (ensures (parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed))) (decreases fuel) =
assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1)
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to'
val parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond))
val parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond))
let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel)
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 33, "end_line": 249, "start_col": 0, "start_line": 240 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> fuel: Prims.nat -> LowParse.Spec.Base.parser (LowParse.Spec.ListUpTo.parse_list_up_to_kind k) (LowParse.Spec.ListUpTo.parse_list_up_to_t cond)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "Prims.nat", "LowParse.Spec.Combinators.parse_synth", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "LowParse.Spec.ListUpTo.synth_list_up_to'" ]
[]
false
false
false
false
false
let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) =
parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel)
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.close_parse_list_up_to
val close_parse_list_up_to (b: bytes) : GTot (n: nat{Seq.length b < n})
val close_parse_list_up_to (b: bytes) : GTot (n: nat{Seq.length b < n})
let close_parse_list_up_to (b: bytes) : GTot (n: nat { Seq.length b < n }) = Seq.length b + 1
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 18, "end_line": 273, "start_col": 0, "start_line": 270 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy) let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed) )) = parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
b: LowParse.Bytes.bytes -> Prims.GTot (n: Prims.nat{FStar.Seq.Base.length b < n})
Prims.GTot
[ "sometrivial" ]
[]
[ "LowParse.Bytes.bytes", "Prims.op_Addition", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.nat", "Prims.b2t", "Prims.op_LessThan" ]
[]
false
false
false
false
false
let close_parse_list_up_to (b: bytes) : GTot (n: nat{Seq.length b < n}) =
Seq.length b + 1
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to
val parse_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond))
val parse_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond))
let parse_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_list_up_to_correct #k #t cond p prf; close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 66, "end_line": 311, "start_col": 0, "start_line": 303 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy) let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed) )) = parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b let close_parse_list_up_to (b: bytes) : GTot (n: nat { Seq.length b < n }) = Seq.length b + 1 let parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to)) = close_by_fuel_correct (parse_list_up_to_kind k) (parse_list_up_to' cond p) close_parse_list_up_to (fun fuel b -> parse_list_up_to'_eq cond p (close_parse_list_up_to b) b; parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_ext cond p prf (close_parse_list_up_to b) fuel b ) (fun fuel -> parser_kind_prop_fuel_complete fuel (parse_list_up_to_kind k) (parse_list_up_to' cond p fuel) )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond cond p -> LowParse.Spec.Base.parser (LowParse.Spec.ListUpTo.parse_list_up_to_kind k) (LowParse.Spec.ListUpTo.parse_list_up_to_t cond)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "LowParse.Spec.ListUpTo.consumes_if_not_cond", "LowParse.Spec.Fuel.close_by_fuel'", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.parse_list_up_to'", "LowParse.Spec.ListUpTo.close_parse_list_up_to", "Prims.unit", "LowParse.Spec.ListUpTo.parse_list_up_to_correct", "LowParse.Spec.ListUpTo.parse_list_up_to_kind" ]
[]
false
false
false
false
false
let parse_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: consumes_if_not_cond cond p) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) =
parse_list_up_to_correct #k #t cond p prf; close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_string
val validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) : Tot (validate_with_action_t (parse_string p terminator) true_inv disjointness_trivial eloc_none false)
val validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) : Tot (validate_with_action_t (parse_string p terminator) true_inv disjointness_trivial eloc_none false)
let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) = LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 74, "end_line": 1730, "start_col": 0, "start_line": 1722 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo unfold let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end inline_for_extraction let validate_list_up_to_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (v: validator p) (r: leaf_reader p) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (h0: HS.mem) (bres: B.pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false )) (ensures (fun h stop h' -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false /\ validate_list_up_to_inv p terminator prf ctxt sl h0 bres h' stop )) = let h = HST.get () in LUT.parse_list_up_to_eq (cond_string_up_to terminator) p prf (I.get_remaining sl h); let position = !* bres in let result = v ctxt error_handler_fn sl sl_len position in B.upd bres 0ul result; if LPE.is_error result then begin true end else begin let value = r sl position in cond_string_up_to terminator value end inline_for_extraction noextract let validate_list_up_to (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) : validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv disjointness_trivial eloc_none false = fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres) ; let result = B.index bres 0ul in HST.pop_frame (); result
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
v: EverParse3d.Actions.Base.validator p -> r: EverParse3d.Actions.Base.leaf_reader p -> terminator: t -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_string p terminator) EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "Prims.eqtype", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.validator", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.validate_weaken", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "EverParse3d.Prelude.cond_string_up_to", "LowParse.Spec.ListUpTo.parse_list_up_to", "LowParse.Bytes.bytes", "LowParse.Spec.Base.consumed_length", "Prims.unit", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_list_up_to", "EverParse3d.Kinds.parse_string_kind", "LowParse.Spec.Base.parser_kind_prop_equiv", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Prelude.cstring", "EverParse3d.Prelude.parse_string" ]
[]
false
false
false
false
false
let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@ erasable]p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) =
LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_chan_inv_auxT
val intro_chan_inv_auxT (#p: _) (#vs #vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c)
val intro_chan_inv_auxT (#p: _) (#vs #vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c)
let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs)
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 89, "end_line": 103, "start_col": 0, "start_line": 94 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Steel.Channel.Simplex.chan_t p -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.chan_t", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.chan_inv_recv", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Channel.Simplex.chan_inv" ]
[]
false
true
false
false
false
let intro_chan_inv_auxT #p (#vs: chan_val) (#vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c) =
intro_exists _ (fun (vr: chan_val) -> ((pts_to c.recv half vr) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)); intro_exists _ (fun (vs: chan_val) -> (pts_to c.send half vs) `star` (chan_inv_recv c vs))
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_correct
val parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: (b: bytes -> x: t -> consumed: consumed_length b -> Lemma (requires (parse p b == Some (x, consumed) /\ (~(cond x)))) (ensures (consumed > 0)))) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to))
val parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: (b: bytes -> x: t -> consumed: consumed_length b -> Lemma (requires (parse p b == Some (x, consumed) /\ (~(cond x)))) (ensures (consumed > 0)))) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to))
let parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to)) = close_by_fuel_correct (parse_list_up_to_kind k) (parse_list_up_to' cond p) close_parse_list_up_to (fun fuel b -> parse_list_up_to'_eq cond p (close_parse_list_up_to b) b; parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_ext cond p prf (close_parse_list_up_to b) fuel b ) (fun fuel -> parser_kind_prop_fuel_complete fuel (parse_list_up_to_kind k) (parse_list_up_to' cond p fuel) )
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 5, "end_line": 301, "start_col": 0, "start_line": 275 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy) let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed) )) = parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b let close_parse_list_up_to (b: bytes) : GTot (n: nat { Seq.length b < n }) = Seq.length b + 1
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> prf: (b: LowParse.Bytes.bytes -> x: t -> consumed: LowParse.Spec.Base.consumed_length b -> FStar.Pervasives.Lemma (requires LowParse.Spec.Base.parse p b == FStar.Pervasives.Native.Some (x, consumed) /\ ~(cond x)) (ensures consumed > 0)) -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parser_kind_prop (LowParse.Spec.ListUpTo.parse_list_up_to_kind k) (LowParse.Spec.Fuel.close_by_fuel' (LowParse.Spec.ListUpTo.parse_list_up_to' cond p) LowParse.Spec.ListUpTo.close_parse_list_up_to))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "LowParse.Bytes.bytes", "LowParse.Spec.Base.consumed_length", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.parse", "FStar.Pervasives.Native.Mktuple2", "Prims.l_not", "Prims.squash", "Prims.op_GreaterThan", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Fuel.close_by_fuel_correct", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to'", "LowParse.Spec.ListUpTo.close_parse_list_up_to", "Prims.nat", "Prims.op_LessThan", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_ext", "LowParse.Spec.ListUpTo.parse_list_up_to'_eq", "LowParse.Spec.Fuel.parser_kind_prop_fuel_complete", "Prims.l_True", "LowParse.Spec.Base.parser_kind_prop", "LowParse.Spec.Fuel.close_by_fuel'" ]
[]
false
false
true
false
false
let parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: (b: bytes -> x: t -> consumed: consumed_length b -> Lemma (requires (parse p b == Some (x, consumed) /\ (~(cond x)))) (ensures (consumed > 0)))) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to)) =
close_by_fuel_correct (parse_list_up_to_kind k) (parse_list_up_to' cond p) close_parse_list_up_to (fun fuel b -> parse_list_up_to'_eq cond p (close_parse_list_up_to b) b; parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_ext cond p prf (close_parse_list_up_to b) fuel b) (fun fuel -> parser_kind_prop_fuel_complete fuel (parse_list_up_to_kind k) (parse_list_up_to' cond p fuel))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_all_bytes
val validate_all_bytes : validate_with_action_t parse_all_bytes true_inv disjointness_trivial eloc_none false
val validate_all_bytes : validate_with_action_t parse_all_bytes true_inv disjointness_trivial eloc_none false
let validate_all_bytes = fun _ _ input input_length start_position -> I.empty input input_length start_position
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 43, "end_line": 1733, "start_col": 0, "start_line": 1732 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo unfold let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end inline_for_extraction let validate_list_up_to_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (v: validator p) (r: leaf_reader p) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (h0: HS.mem) (bres: B.pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false )) (ensures (fun h stop h' -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false /\ validate_list_up_to_inv p terminator prf ctxt sl h0 bres h' stop )) = let h = HST.get () in LUT.parse_list_up_to_eq (cond_string_up_to terminator) p prf (I.get_remaining sl h); let position = !* bres in let result = v ctxt error_handler_fn sl sl_len position in B.upd bres 0ul result; if LPE.is_error result then begin true end else begin let value = r sl position in cond_string_up_to terminator value end inline_for_extraction noextract let validate_list_up_to (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) : validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv disjointness_trivial eloc_none false = fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres) ; let result = B.index bres 0ul in HST.pop_frame (); result let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) = LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
EverParse3d.Actions.Base.validate_with_action_t EverParse3d.Prelude.parse_all_bytes EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.InputStream.Base.empty", "FStar.UInt64.t" ]
[]
false
false
false
false
false
let validate_all_bytes =
fun _ _ input input_length start_position -> I.empty input input_length start_position
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_return
val action_return (#a:Type) (x:a) : action true_inv disjointness_trivial eloc_none false a
val action_return (#a:Type) (x:a) : action true_inv disjointness_trivial eloc_none false a
let action_return (#a:Type) (x:a) = fun _ _ _ _ _ _ -> x
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 24, "end_line": 1745, "start_col": 0, "start_line": 1743 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo unfold let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end inline_for_extraction let validate_list_up_to_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (v: validator p) (r: leaf_reader p) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (h0: HS.mem) (bres: B.pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false )) (ensures (fun h stop h' -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false /\ validate_list_up_to_inv p terminator prf ctxt sl h0 bres h' stop )) = let h = HST.get () in LUT.parse_list_up_to_eq (cond_string_up_to terminator) p prf (I.get_remaining sl h); let position = !* bres in let result = v ctxt error_handler_fn sl sl_len position in B.upd bres 0ul result; if LPE.is_error result then begin true end else begin let value = r sl position in cond_string_up_to terminator value end inline_for_extraction noextract let validate_list_up_to (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) : validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv disjointness_trivial eloc_none false = fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres) ; let result = B.index bres 0ul in HST.pop_frame (); result let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) = LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _ let validate_all_bytes = fun _ _ input input_length start_position -> I.empty input input_length start_position let validate_all_zeros = validate_list (validate_filter "parse_zeros" validate____UINT8 read____UINT8 is_zero "check if zero" "") //////////////////////////////////////////////////////////////////////////////// noextract
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: a -> EverParse3d.Actions.Base.action EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false a
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t" ]
[]
false
false
false
false
false
let action_return (#a: Type) (x: a) =
fun _ _ _ _ _ _ -> x
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.ptr_inv_elim
val ptr_inv_elim (x: B.pointer 'a) : Lemma (ensures forall h. ptr_inv x h ==> B.live h x)
val ptr_inv_elim (x: B.pointer 'a) : Lemma (ensures forall h. ptr_inv x h ==> B.live h x)
let ptr_inv_elim (x:B.pointer 'a) : Lemma (ensures forall h. ptr_inv x h ==> B.live h x) = introduce forall h. ptr_inv x h ==> B.live h x with assert (ptr_inv x h ==> B.live h x) by (T.norm [delta])
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 1816, "start_col": 0, "start_line": 1811 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end inline_for_extraction noextract let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end inline_for_extraction noextract let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : validate_with_action_t (parse_weaken p k') inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_left #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k' k) /// Parser: weakening kinds inline_for_extraction noextract let validate_weaken_right #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) #nz' #wk' (k':parser_kind nz' wk') = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position noextract inline_for_extraction let validate_ite e p1 v1 p2 v2 = fun ctxt error_handler_fn input input_len start_position -> if e then validate_drop (v1 ()) ctxt error_handler_fn input input_len start_position else validate_drop (v2 ()) ctxt error_handler_fn input input_len start_position module LPLL = LowParse.Spec.List unfold let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (disj: disjointness_pre) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv h0 /\ disj /\ loc_not_unused_in h0 `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ app_loc ctxt l `loc_disjoint` loc_buffer bres /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.loc_buffer bres `B.loc_disjoint` I.footprint sl /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ modifies loc_none h0 h1 /\ ( if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~ (valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0)) ) /\ modifies (app_loc ctxt l `loc_union` loc_buffer bres `loc_union` I.perm_footprint sl) h1 h inline_for_extraction noextract let validate_list_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (bres: pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv disj l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv disj l g0 g1 ctxt sl bres h' res )) = let h = HST.get () in LPLL.parse_list_eq p (I.get_remaining sl h); let position = !* bres in if not (I.has sl sl_len position 1uL) then true else begin let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in (Ghost.reveal g0) h1; let result = validate_drop v ctxt error_handler_fn sl sl_len position in upd bres 0ul result; LPE.is_error result end inline_for_extraction noextract let validate_list' (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) (ctxt: app_ctxt) (error_handler_fn: error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (pos: LPE.pos_t) : HST.Stack U64.t (requires (fun h -> inv h /\ disj /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ B.live h ctxt /\ I.live sl h /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in inv h' /\ B.live h' ctxt /\ I.live sl h' /\ begin let s' = I.get_remaining sl h' in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end /\ begin match LP.parse (LPLL.parse_list p) s with | None -> LPE.is_success res == false | Some (_, len) -> if LPE.is_success res then I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) /\ U64.v res == Seq.length (I.get_read sl h') else LPE.get_validator_error_kind res == LPE.get_validator_error_kind LPE.validator_error_action_failed end /\ (LPE.is_success res == false ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h h' )) = let h0 = HST.get () in let g0 = Ghost.hide h0 in HST.push_frame (); let h02 = HST.get () in fresh_frame_modifies h0 h02; let result = alloca pos 1ul in let h1 = HST.get () in let g1 = Ghost.hide h1 in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_inv p inv disj l g0 g1 ctxt sl result) (fun _ -> validate_list_body v g0 g1 ctxt error_handler_fn sl sl_len result); let finalResult = index result 0ul in let h2 = HST.get () in HST.pop_frame (); let h' = HST.get () in assert (B.modifies (app_loc ctxt l `B.loc_union` I.perm_footprint sl) h0 h'); LP.parser_kind_prop_equiv LPLL.parse_list_kind (LPLL.parse_list p); finalResult inline_for_extraction noextract let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.List.parse_list p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position #push-options "--z3rlimit 32" #restart-solver module LPLF = LowParse.Low.FLData noextract inline_for_extraction let validate_fldata_consumes_all (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPLF.parse_fldata_consumes_all_correct p (U32.v n) (I.get_remaining input h); let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in I.is_prefix_of_prop truncatedInput input h3; res end #pop-options #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_fldata (n:U32.t) (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #disj #l #ar (v: validate_with_action_t' p inv disj l ar) : validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasEnoughBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasEnoughBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else begin let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; I.is_prefix_of_prop truncatedInput input h2; assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)); let res = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h h3; I.is_prefix_of_prop truncatedInput input h3; if LPE.is_error res then res else begin let stillHasBytes = I.has truncatedInput truncatedInputLength res 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding res else res end end #pop-options noextract inline_for_extraction let validate_nlist (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = validate_weaken #false #WeakKindStrongPrefix #(LowParse.Spec.FLData.parse_fldata_kind (U32.v n) LowParse.Spec.List.parse_list_kind) #(list t) (validate_fldata_consumes_all n (validate_list v)) kind_nlist inline_for_extraction noextract let validate_total_constant_size_no_read' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : validate_with_action_t' p inv disj l true = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LP.parser_kind_prop_equiv k p; let hasBytes = I.has input input_length pos sz in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h h2; if hasBytes then pos `U64.add` sz else LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos inline_for_extraction noextract let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv disj l : Tot (validate_with_action_t p inv disj l true) = validate_total_constant_size_no_read' p sz u inv disj l inline_for_extraction noextract let validate_nlist_total_constant_size_mod_ok (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 /\ U32.v n % k.LP.parser_kind_low == 0 )) (ensures (fun _ -> True)) = [@inline_let] let _ = parse_nlist_total_fixed_size_kind_correct n p in validate_total_constant_size_no_read' (LP.strengthen (LP.total_constant_size_parser_kind (U32.v n)) (parse_nlist n p)) (Cast.uint32_to_uint64 n) () inv disj l inline_for_extraction noextract let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0 )) (ensures (fun _ -> True)) = (fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = FStar.HyperStack.ST.get () in [@inline_let] let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq' ; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == FStar.List.Tot.length l `Prims.op_Multiply` k.LP.parser_kind_low) ; FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low ; assert (U32.v n % k.LP.parser_kind_low == 0) in [@inline_let] let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos ) inline_for_extraction noextract let validate_nlist_total_constant_size' (n:U32.t) #wk (#k:parser_kind true wk) #t (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ k.parser_kind_metadata == Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input start_position -> // n is not an integer constant, so we need to eta-expand and swap fun and if if n `U32.rem` U32.uint_to_t k.LP.parser_kind_low = 0ul then validate_nlist_total_constant_size_mod_ok n p inv disj l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv disj l ctxt error_handler_fn input start_position inline_for_extraction noextract let validate_nlist_total_constant_size (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) (#t: Type) (p:parser k t) inv disj l : Pure (validate_with_action_t (parse_nlist n p) inv disj l true) (requires ( let open LP in k.parser_kind_subkind = Some ParserStrong /\ k.parser_kind_high = Some k.parser_kind_low /\ k.parser_kind_metadata = Some ParserKindMetadataTotal /\ k.parser_kind_low < 4294967296 )) (ensures (fun _ -> True)) = if if k.LP.parser_kind_low = 1 then true else if n_is_const then U32.v n % k.LP.parser_kind_low = 0 else false then validate_nlist_total_constant_size_mod_ok n p inv disj l else if if n_is_const then U32.v n % k.LP.parser_kind_low <> 0 else false then validate_nlist_constant_size_mod_ko n p inv disj l else validate_nlist_total_constant_size' n p inv disj l noextract inline_for_extraction let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #disj #l #ar (v: validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_nlist n p) inv disj l false) = if let open LP in k.parser_kind_subkind = Some ParserStrong && k.parser_kind_high = Some k.parser_kind_low && k.parser_kind_metadata = Some ParserKindMetadataTotal && k.parser_kind_low < 4294967296 then validate_drop (validate_nlist_total_constant_size n_is_const n p inv disj l) else validate_nlist n v #push-options "--z3rlimit_factor 16 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_at_most (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let _ = I.empty truncatedInput truncatedInputLength result in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; let _ = I.is_prefix_of_prop truncatedInput input h4 in pos `U64.add` Cast.uint32_to_uint64 n end #pop-options #push-options "--z3rlimit 128 --z3cliopt smt.arith.nl=false" #restart-solver noextract inline_for_extraction let validate_t_exact (n:U32.t) #nz #wk (#k:parser_kind nz wk) (#t:_) (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t (parse_t_exact n p) inv disj l false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in let hasBytes = I.has input input_length pos (Cast.uint32_to_uint64 n) in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if not hasBytes then LPE.set_validator_error_pos LPE.validator_error_not_enough_data pos else let truncatedInput = I.truncate input pos (Cast.uint32_to_uint64 n) in let truncatedInputLength = I.truncate_len input pos (Cast.uint32_to_uint64 n) truncatedInput in let h2 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h2 in let _ = I.is_prefix_of_prop truncatedInput input h2 in let _ = assert (I.get_remaining truncatedInput h2 `Seq.equal` Seq.slice (I.get_remaining input h) 0 (U32.v n)) in [@inline_let] let _ = LPC.nondep_then_eq p parse_all_bytes (I.get_remaining truncatedInput h2) in let result = validate_drop v ctxt error_handler_fn truncatedInput truncatedInputLength pos in let h3 = HST.get () in let _ = I.is_prefix_of_prop truncatedInput input h3 in if LPE.is_error result then result else begin let stillHasBytes = I.has truncatedInput truncatedInputLength result 1uL in let h4 = HST.get () in modifies_address_liveness_insensitive_unused_in h h4; I.is_prefix_of_prop truncatedInput input h4; if stillHasBytes then LPE.set_validator_error_pos LPE.validator_error_unexpected_padding result else result end #pop-options inline_for_extraction noextract let validate_with_comment (c:string) #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj #l #ar (v:validate_with_action_t p inv disj l ar) : validate_with_action_t p inv disj l ar = fun ctxt error_handler_fn input input_length start_position -> LowParse.Low.Base.comment c; v ctxt error_handler_fn input input_length start_position inline_for_extraction noextract let validate_weaken_inv_loc #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #disj (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (disj':_{ disj' `imp_disjointness` disj}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t p inv' disj' l' ar) = v //////////////////////////////////////////////////////////////////////////////// //Base types //////////////////////////////////////////////////////////////////////////////// inline_for_extraction noextract let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos inline_for_extraction noextract let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim () inline_for_extraction noextract let validate____UINT8 : validator parse____UINT8 = validate_with_comment "Checking that we have enough space for a UINT8, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8 1uL () _ _ _) inline_for_extraction noextract let lift_reader (#nz: _) (#k: parser_kind nz WeakKindStrongPrefix) (#t: _) (p: parser k t) (r: LPL.leaf_reader p) (sz32: U32.t) (sz: U64.t) : Pure (leaf_reader p) (requires ( U32.v sz32 == U64.v sz /\ U64.v sz > 0 /\ k.LP.parser_kind_subkind == Some LP.ParserStrong /\ k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low = U64.v sz )) (ensures (fun _ -> True)) = fun input pos -> LP.parser_kind_prop_equiv k p; I.read t k p r input pos sz inline_for_extraction noextract let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _ _) inline_for_extraction noextract let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL inline_for_extraction noextract let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _ _) inline_for_extraction noextract let read____UINT16BE : leaf_reader parse____UINT16BE = lift_reader _ LowParse.Low.Int.read_u16 2ul 2uL inline_for_extraction noextract let validate____UINT32BE : validator parse____UINT32BE = validate_with_comment "Checking that we have enough space for a UINT32BE, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32BE 4uL () _ _ _) inline_for_extraction noextract let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL inline_for_extraction noextract let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _ _) inline_for_extraction noextract let read____UINT64BE : leaf_reader parse____UINT64BE = lift_reader _ LowParse.Low.Int.read_u64 8ul 8uL inline_for_extraction noextract let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _ _) inline_for_extraction noextract let read____UINT16 : leaf_reader parse____UINT16 = lift_reader _ LowParse.Low.BoundedInt.read_u16_le 2ul 2uL inline_for_extraction noextract let validate____UINT32 : validator parse____UINT32 = validate_with_comment "Checking that we have enough space for a UINT32, i.e., 4 bytes" (validate_total_constant_size_no_read parse____UINT32 4uL () _ _ _) inline_for_extraction noextract let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL inline_for_extraction noextract let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _ _) inline_for_extraction noextract let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL inline_for_extraction noextract let validate_unit = fun _ _ input _ start_position -> start_position inline_for_extraction noextract let read_unit = fun input pos -> () inline_for_extraction noextract let validate_unit_refinement (f:unit -> bool) (cf:string) : validator (parse_unit `parse_filter` f) = fun _ _ input _ start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq parse_unit f (I.get_remaining input h); LowStar.Comment.comment cf; if f () then pos else LPE.set_validator_error_pos LPE.validator_error_constraint_failed pos (* Reimplement validate_list_up_to with readability (but no actions) *) module LUT = LowParse.Low.ListUpTo unfold let validate_list_up_to_inv (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (ctxt: app_ctxt) (sl: input_buffer_t) (h0: HS.mem) (bres: B.pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 = let res = B.deref h bres in let q = LUT.parse_list_up_to (cond_string_up_to terminator) p prf in B.live h0 bres /\ I.live sl h0 /\ I.live sl h /\ B.loc_disjoint (I.footprint sl) (B.loc_buffer bres `B.loc_union` app_loc ctxt loc_none) /\ B.loc_disjoint (B.loc_buffer bres) (app_loc ctxt loc_none) /\ B.live h0 ctxt /\ B.live h ctxt /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt loc_none) /\ B.modifies (B.loc_buffer bres `B.loc_union` I.perm_footprint sl `B.loc_union` app_loc ctxt loc_none) h0 h /\ begin let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) /\ begin if LPE.is_error res then // validation *or action* failed stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse q s)) else U64.v res == Seq.length (I.get_read sl h) /\ begin if stop then valid_consumed q h0 h sl else match LP.parse q s, LP.parse q s' with | None, None -> True | Some (_, consumed), Some (_, consumed') -> consumed' + Seq.length s - Seq.length s' == consumed | _ -> False end end end inline_for_extraction let validate_list_up_to_body (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) (v: validator p) (r: leaf_reader p) (ctxt:app_ctxt) (error_handler_fn:error_handler) (sl: input_buffer_t) (sl_len: I.tlen sl) (h0: HS.mem) (bres: B.pointer U64.t) : HST.Stack bool (requires (fun h -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false )) (ensures (fun h stop h' -> validate_list_up_to_inv p terminator prf ctxt sl h0 bres h false /\ validate_list_up_to_inv p terminator prf ctxt sl h0 bres h' stop )) = let h = HST.get () in LUT.parse_list_up_to_eq (cond_string_up_to terminator) p prf (I.get_remaining sl h); let position = !* bres in let result = v ctxt error_handler_fn sl sl_len position in B.upd bres 0ul result; if LPE.is_error result then begin true end else begin let value = r sl position in cond_string_up_to terminator value end inline_for_extraction noextract let validate_list_up_to (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) (prf: LUT.consumes_if_not_cond (cond_string_up_to terminator) p) : validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv disjointness_trivial eloc_none false = fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres) ; let result = B.index bres 0ul in HST.pop_frame (); result let validate_string (#k: parser_kind true WeakKindStrongPrefix) (#t: eqtype) (#[@@@erasable] p: parser k t) (v: validator p) (r: leaf_reader p) (terminator: t) = LP.parser_kind_prop_equiv k p; validate_weaken (validate_list_up_to v r terminator (fun _ _ _ -> ())) _ let validate_all_bytes = fun _ _ input input_length start_position -> I.empty input input_length start_position let validate_all_zeros = validate_list (validate_filter "parse_zeros" validate____UINT8 read____UINT8 is_zero "check if zero" "") //////////////////////////////////////////////////////////////////////////////// noextract inline_for_extraction let action_return (#a:Type) (x:a) = fun _ _ _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) (#invf:slice_inv) #disjf (#lf:eloc) #bf (#a:Type) (f: action invf disjf lf bf a) (#invg:slice_inv) #disjg (#lg:eloc) #bg (#b:Type) (g: (a -> action invg disjg lg bg b)) = fun ctxt error_handler_fn input input_length pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt error_handler_fn input input_length pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt error_handler_fn input input_length pos posf noextract inline_for_extraction let action_seq (#invf:slice_inv) #disjf (#lf:eloc) #bf (#a:Type) (f: action invf disjf lf bf a) (#invg:slice_inv) #disjg (#lg:eloc) #bg (#b:Type) (g: action invg disjg lg bg b) = fun ctxt error_handler_fn input input_length pos posf -> let h0 = HST.get () in let _ = f ctxt error_handler_fn input input_length pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt error_handler_fn input input_length pos posf noextract inline_for_extraction let action_ite (#invf:slice_inv) #disjf (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action invf disjf lf bf a) (#invg:slice_inv) #disjg (#lg:eloc) #bg (else_: squash (not guard) -> action invg disjg lg bg a) = fun ctxt error_handler_fn input input_length pos posf -> if guard then then_ () ctxt error_handler_fn input input_length pos posf else else_ () ctxt error_handler_fn input input_length pos posf noextract inline_for_extraction let action_abort = fun _ _ _ _ _ _ -> false noextract inline_for_extraction let action_field_pos_64 = fun _ _ _ _ pos _ -> pos (* FIXME: this is now unsound in general (only valid for flat buffer) noextract inline_for_extraction let action_field_ptr #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (u:unit) : action p true_inv eloc_none true LPL.puint8 = fun input startPosition _ -> let open LowParse.Slice in LPL.offset input (LPL.uint64_to_uint32 startPosition) *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "FStar.Tactics", "short_module": "T" }, { "abbrev": true, "full_module": "LowParse.Low.ListUpTo", "short_module": "LUT" }, { "abbrev": true, "full_module": "LowParse.Low.FLData", "short_module": "LPLF" }, { "abbrev": true, "full_module": "LowParse.Spec.List", "short_module": "LPLL" }, { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: LowStar.Buffer.pointer 'a -> FStar.Pervasives.Lemma (ensures forall (h: FStar.Monotonic.HyperStack.mem). EverParse3d.Actions.Base.ptr_inv x h ==> LowStar.Monotonic.Buffer.live h x)
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowStar.Buffer.pointer", "FStar.Classical.Sugar.forall_intro", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "EverParse3d.Actions.Base.ptr_inv", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "FStar.Tactics.Effect.assert_by_tactic", "Prims.unit", "FStar.Stubs.Tactics.V1.Builtins.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.delta", "Prims.Nil", "Prims.squash", "Prims.l_True", "Prims.l_Forall", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
let ptr_inv_elim (x: B.pointer 'a) : Lemma (ensures forall h. ptr_inv x h ==> B.live h x) =
introduce forall h . ptr_inv x h ==> B.live h x with FStar.Tactics.Effect.assert_by_tactic (ptr_inv x h ==> B.live h x) (fun _ -> (); (T.norm [delta]))
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_chan_inv_stepT
val intro_chan_inv_stepT (#p: _) (c: chan_t p) (vs vr: chan_val) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_step vr vs)) (fun _ -> chan_inv c)
val intro_chan_inv_stepT (#p: _) (c: chan_t p) (vs vr: chan_val) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_step vr vs)) (fun _ -> chan_inv c)
let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 25, "end_line": 112, "start_col": 0, "start_line": 105 }
(* 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.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs)
{ "checked_file": "/", "dependencies": [ "Steel.Utils.fst.checked", "Steel.SpinLock.fsti.checked", "Steel.MonotonicHigherReference.fsti.checked", "Steel.Memory.fsti.checked", "Steel.HigherReference.fsti.checked", "Steel.FractionalPermission.fst.checked", "Steel.Effect.Atomic.fsti.checked", "Steel.Effect.fsti.checked", "Steel.Channel.Protocol.fst.checked", "prims.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": true, "source_file": "Steel.Channel.Simplex.fst" }
[ { "abbrev": true, "full_module": "Steel.HigherReference", "short_module": "H" }, { "abbrev": true, "full_module": "Steel.MonotonicHigherReference", "short_module": "MRef" }, { "abbrev": false, "full_module": "Steel.FractionalPermission", "short_module": null }, { "abbrev": false, "full_module": "Steel.HigherReference", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Effect.Atomic", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.SpinLock", "short_module": null }, { "abbrev": true, "full_module": "Steel.Channel.Protocol", "short_module": "P" }, { "abbrev": false, "full_module": "Steel.Effect", "short_module": null }, { "abbrev": false, "full_module": "Steel.Memory", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel.Protocol", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "Steel.Channel", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
c: Steel.Channel.Simplex.chan_t p -> vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
Steel.Effect.SteelT
[]
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.intro_chan_inv_auxT", "Prims.unit", "Steel.Channel.Simplex.intro_chan_inv_cond_stepT", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv_step", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop" ]
[]
false
true
false
false
false
let intro_chan_inv_stepT #p (c: chan_t p) (vs: chan_val) (vr: chan_val) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_step vr vs)) (fun _ -> chan_inv c) =
intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_fuel_length
val parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: (b: bytes -> x: t -> consumed: consumed_length b -> Lemma (requires (parse p b == Some (x, consumed) /\ (~(cond x)))) (ensures (consumed > 0)))) (fuel: nat) (b: bytes) : Lemma (match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b)
val parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: (b: bytes -> x: t -> consumed: consumed_length b -> Lemma (requires (parse p b == Some (x, consumed) /\ (~(cond x)))) (ensures (consumed > 0)))) (fuel: nat) (b: bytes) : Lemma (match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b)
let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 195, "start_col": 0, "start_line": 163 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> p: LowParse.Spec.Base.parser k t { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> prf: (b: LowParse.Bytes.bytes -> x: t -> consumed: LowParse.Spec.Base.consumed_length b -> FStar.Pervasives.Lemma (requires LowParse.Spec.Base.parse p b == FStar.Pervasives.Native.Some (x, consumed) /\ ~(cond x)) (ensures consumed > 0)) -> fuel: Prims.nat -> b: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures ((match LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel) b with | FStar.Pervasives.Native.None #_ -> Prims.l_True | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ xy _) -> FStar.List.Tot.Base.length (FStar.Pervasives.Native.fst xy) <= FStar.Seq.Base.length b) <: Type0))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "LowParse.Bytes.bytes", "LowParse.Spec.Base.consumed_length", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.parse", "FStar.Pervasives.Native.Mktuple2", "Prims.l_not", "Prims.squash", "Prims.op_GreaterThan", "Prims.Nil", "FStar.Pervasives.pattern", "Prims.nat", "Prims.op_Equality", "Prims.int", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_length", "Prims.op_Subtraction", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "FStar.Seq.Base.length", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_eq", "Prims.l_True", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "Prims.op_LessThanOrEqual", "FStar.List.Tot.Base.length", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "LowParse.Spec.ListUpTo.llist" ]
[ "recursion" ]
false
false
true
false
false
let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t {k.parser_kind_subkind <> Some ParserConsumesAll}) (prf: (b: bytes -> x: t -> consumed: consumed_length b -> Lemma (requires (parse p b == Some (x, consumed) /\ (~(cond x)))) (ensures (consumed > 0)))) (fuel: nat) (b: bytes) : Lemma (match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b) =
parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else (prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_with_dep_action
val validate_with_dep_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] disja:disjointness_pre) (#[@@@erasable] la:eloc) (a: t -> action inva disja la b bool) : validate_with_action_t #nz p (conj_inv inv inva) (conj_disjointness disj disja) (eloc_union l la) false
val validate_with_dep_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] disja:disjointness_pre) (#[@@@erasable] la:eloc) (a: t -> action inva disja la b bool) : validate_with_action_t #nz p (conj_inv inv inva) (conj_disjointness disj disja) (eloc_union l la) false
let validate_with_dep_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin [@(rename_let ("" ^ name))] let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res end
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 837, "start_col": 0, "start_line": 813 }
module EverParse3d.Actions.Base friend EverParse3d.Kinds friend EverParse3d.Prelude open FStar.HyperStack.ST open LowStar.Buffer open LowStar.BufferOps module B = LowStar.Buffer module I = EverParse3d.InputStream.Base module HS = FStar.HyperStack module HST = FStar.HyperStack.ST module CP = EverParse3d.CopyBuffer module AppCtxt = EverParse3d.AppCtxt module LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses open FStar.FunctionalExtensionality module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude module F = FStar.FunctionalExtensionality let hinv = HS.mem ^-> prop let liveness_inv = i:hinv { forall l h0 h1. {:pattern (i h1); (modifies l h0 h1)} i h0 /\ modifies l h0 h1 /\ address_liveness_insensitive_locs `loc_includes` l ==> i h1 } let mem_inv = liveness_inv let slice_inv = mem_inv let inv_implies (inv0 inv1:slice_inv) = forall h. inv0 h ==> inv1 h let true_inv : slice_inv = F.on HS.mem #prop (fun _ -> True) let conj_inv (i0 i1:slice_inv) : slice_inv = F.on HS.mem #prop (fun h -> i0 h /\ i1 h) let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l }) let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2 let eloc_none : eloc = B.loc_none let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True let eloc_disjoint (l1 l2:eloc) = B.loc_disjoint l1 l2 /\ True let inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let conj_inv_true_left_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv true_inv i) i let conj_inv_true_right_unit i = FStar.PredicateExtensionality.predicateExtensionality _ (conj_inv i true_inv) i let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let eloc_union_none_left_unit l = () let eloc_union_none_right_unit l = () let disjointness_pre = prop let disjointness_trivial = True let disjoint l1 l2 = eloc_disjoint l1 l2 let conj_disjointness p1 p2 = p1 /\ p2 let imp_disjointness p1 p2 = p1 ==> p2 let disjoint_none_r l = FStar.PropositionalExtensionality.apply (disjoint l eloc_none) (disjointness_trivial) let disjoint_none_l l = FStar.PropositionalExtensionality.apply (disjoint eloc_none l) (disjointness_trivial) let conj_disjointness_trivial_left_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (disjointness_trivial `conj_disjointness` d) d let conj_disjointness_trivial_right_unit (d:disjointness_pre) = FStar.PropositionalExtensionality.apply (d `conj_disjointness` disjointness_trivial) d let imp_disjointness_refl (d:disjointness_pre) = () let index_equations () = introduce forall d. _ with conj_inv_true_left_unit d; introduce forall d. _ with conj_inv_true_right_unit d; introduce forall l. _ with eloc_union_none_right_unit l; introduce forall l. _ with eloc_union_none_left_unit l; introduce forall l. _ with disjoint_none_r l; introduce forall l. _ with disjoint_none_l l; introduce forall d. _ with conj_disjointness_trivial_left_unit d; introduce forall d. _ with conj_disjointness_trivial_right_unit d; introduce forall d. _ with imp_disjointness_refl d; introduce forall i. _ with inv_implies_refl i; introduce forall i. _ with inv_implies_true i; introduce forall i0 i1 i2. (i0 `inv_implies` i1 /\ i0 `inv_implies` i2) ==> (i0 `inv_implies` (i1 `conj_inv` i2)) with introduce _ ==> _ with _ . inv_implies_conj i0 i1 i2 () (); introduce forall l. _ with eloc_includes_none l; introduce forall l0 l1 l2. (l0 `eloc_includes` l1 /\ l0 `eloc_includes` l2) ==> (l0 `eloc_includes` (l1 `eloc_union` l2)) with introduce _ ==> _ with _ . eloc_includes_union l0 l1 l2 () (); introduce forall l. _ with eloc_includes_refl l let bpointer a = B.pointer a let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x let ptr_inv #a (x:B.pointer a) : slice_inv = F.on HS.mem #prop (fun h -> B.live h x /\ True) let app_ctxt = AppCtxt.app_ctxt let app_loc (x:AppCtxt.app_ctxt) (l:eloc) : eloc = AppCtxt.properties x; AppCtxt.loc_of x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t inline_for_extraction let error_handler = typename:string -> fieldname:string -> error_reason:string -> error_code:U64.t -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> Stack unit (requires fun h -> I.live sl h /\ true_inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt eloc_none /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt eloc_none /\ app_loc ctxt eloc_none `loc_disjoint` I.footprint sl /\ U64.v pos <= Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt eloc_none) h0 h1 /\ B.live h1 ctxt /\ true_inv h1) let action inv disj l on_success a = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> error_handler_fn : error_handler -> sl: input_buffer_t -> len: I.tlen sl -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ app_loc ctxt l `loc_disjoint` I.footprint sl /\ U64.v pos <= U64.v posf /\ U64.v posf == Seq.length (I.get_read sl h) ) (ensures fun h0 _ h1 -> let sl = Ghost.reveal sl in modifies (app_loc ctxt l) h0 h1 /\ B.live h1 ctxt /\ inv h1) module LP = LowParse.Spec.Base module LPL = LowParse.Low.Base unfold let valid_consumed (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (h': HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ I.live sl h' /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len) -> I.get_remaining sl h' `Seq.equal` Seq.slice s len (Seq.length s) end end unfold let valid_length (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) (len: int) : Tot prop = I.live sl h /\ begin let s = I.get_remaining sl h in begin match LP.parse p s with | None -> False | Some (_, len') -> len == len' end end let valid (#input_buffer_t: Type0) (# [tcresolve ()] inst : I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop = I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h)) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (disj:disjointness_pre) (l:eloc) (allow_reading:bool) : Type = (# [EverParse3d.Util.solve_from_ctx ()] I.extra_t #input_buffer_t) -> (ctxt: app_ctxt) -> (error_handler_fn : error_handler) -> (sl: input_buffer_t) -> (len: I.tlen sl) -> (pos: LPE.pos_t) -> Stack U64.t (requires fun h -> I.live sl h /\ disj /\ inv h /\ B.live h ctxt /\ loc_not_unused_in h `loc_includes` app_loc ctxt l /\ address_liveness_insensitive_locs `loc_includes` app_loc ctxt l /\ U64.v pos == Seq.length (I.get_read sl h) /\ app_loc ctxt l `loc_disjoint` I.footprint sl ) (ensures fun h res h' -> I.live sl h' /\ modifies (app_loc ctxt l `loc_union` I.perm_footprint sl) h h' /\ inv h' /\ B.live h' ctxt /\ (((~ allow_reading) \/ LPE.is_error res) ==> U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h')) /\ begin let s = I.get_remaining sl h in if LPE.is_success res then begin if allow_reading then U64.v res >= U64.v pos /\ valid_length p h sl (U64.v res - U64.v pos) /\ I.get_remaining sl h' == s else valid_consumed p h h' sl end else let s' = I.get_remaining sl h' in (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> None? (LP.parse p s)) /\ Seq.length s' <= Seq.length s /\ s' `Seq.equal` Seq.slice s (Seq.length s - Seq.length s') (Seq.length s) end ) let validate_with_action_t p inv disj l allow_reading = validate_with_action_t' p inv disj l allow_reading let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos let act_with_comment s res a = fun ctxt err sl len pos posf -> LPL.comment s; a ctxt err sl len pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [EverParse3d.Util.solve_from_ctx ()] _extra_t : I.extra_t #input_buffer_t ) -> (sl: input_buffer_t) -> (pos: LPE.pos_t) -> Stack t (requires (fun h -> valid p h sl /\ U64.v pos == Seq.length (I.get_read sl h) )) (ensures (fun h res h' -> let s = I.get_remaining sl h in I.live sl h' /\ modifies (I.perm_footprint sl) h h' /\ begin match LP.parse p s with | None -> False | Some (y, len) -> res == y /\ I.get_remaining sl h' == Seq.slice s len (Seq.length s) end )) #push-options "--z3rlimit 32" inline_for_extraction noextract let validate_with_success_action' (name: string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1:_) (#disj1:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 disj1 l1 false) (#inv2:_) (#disj2:_) (#l2:eloc) #b (a:action inv2 disj2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ name))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then [@(rename_let ("action_success_" ^ name))] let b = a ctxt error_handler_fn input input_length pos0 pos1 in let h2 = HST.get () in modifies_address_liveness_insensitive_unused_in h1 h2; if not b then LPE.set_validator_error_pos LPE.validator_error_action_failed pos1 else pos1 else pos1 inline_for_extraction noextract let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (v: validate_with_action_t' p inv disj l true) : Tot (validate_with_action_t' p inv disj l false) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let res = v ctxt error_handler_fn input input_length pos in I.skip_if_success input pos res; res inline_for_extraction noextract let validate_drop (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv disj l allow_reading) : Tot (validate_with_action_t' p inv disj l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a inline_for_extraction noextract let validate_with_error_handler (typename:string) (fieldname:string) #nz #wk (#k1:parser_kind nz wk) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar) : validate_with_action_t p1 inv1 disj1 l1 ar = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h0 = HST.get () in [@(rename_let ("positionAfter" ^ typename))] let pos1 = v1 ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_success pos1 then pos1 else ( error_handler_fn typename fieldname (LPE.error_reason_of_result pos1) (LPE.get_validator_error_kind pos1) ctxt input pos0; pos1 ) inline_for_extraction noextract let validate_ret : validate_with_action_t (parse_ret ()) true_inv disjointness_trivial eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position #push-options "--z3rlimit 32" module LPC = LowParse.Spec.Combinators inline_for_extraction noextract let validate_pair (name1: string) #nz1 (#k1:parser_kind nz1 WeakKindStrongPrefix) #t1 (#p1:parser k1 t1) (#inv1 #disj1:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 disj1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2 #disj2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 disj2 l2 ar2) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.nondep_then_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = validate_drop v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h h1; if LPE.is_error pos1 then pos1 else validate_drop v2 ctxt error_handler_fn input input_length pos1 inline_for_extraction noextract let validate_dep_pair (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_dtuple2_eq p1 p2 (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name1))] let pos1 = v1 ctxt error_handler_fn input input_length pos in let h1 = HST.get() in if LPE.is_error pos1 then begin pos1 end else [@(rename_let ("" ^ name1))] let x = r1 input pos in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in validate_drop (v2 x) ctxt error_handler_fn input input_length pos1 #pop-options #push-options "--z3rlimit 64" #restart-solver inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action' (name1: string) (#nz1: _) (#k1:parser_kind nz1 _) (#t1: _) (#p1:parser k1 t1) (#inv1 #disj1 #l1: _) (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin assert (I.get_remaining input h1 == I.get_remaining input h0); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in let h2 = HST.get() in if LPE.is_error res1 then res1 else begin modifies_address_liveness_insensitive_unused_in h1 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed res1 //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action_total_zero_parser' (name1: string) (#nz1: _) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1: _) (#p1:parser k1 t1) (r1: leaf_reader p1) (inv1 disj1 l1: _) (f: t1 -> bool) (#inv1' #disj1' #l1' #b: _) (a:t1 -> action inv1' disj1' l1' b bool) (#nz2 #wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2 #disj2 #l2 #ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (conj_disjointness disj1 (conj_disjointness disj1' disj2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h2; if not (a field_value ctxt error_handler_fn input input_length startPosition res1) then LPE.set_validator_error_pos LPE.validator_error_action_failed startPosition //action failed else begin let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end end inline_for_extraction noextract let validate_dep_pair_with_refinement_and_action (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_and_action_total_zero_parser' name1 r1 inv1 disj1 l1 f a v2 else validate_dep_pair_with_refinement_and_action' name1 v1 r1 f a v2 inline_for_extraction noextract let validate_dep_pair_with_action #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) #inv1' #disj1' #l1' #b (a:t1 -> action inv1' disj1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ p1 #_ #t2 p2 (I.get_remaining input h0); let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin let field_value = r1 input startPosition in let h2 = HST.get() in modifies_address_liveness_insensitive_unused_in h1 h2; let action_result = a field_value ctxt error_handler_fn input input_length startPosition res in let h3 = HST.get () in modifies_address_liveness_insensitive_unused_in h2 h3; if not action_result then LPE.set_validator_error_pos LPE.validator_error_action_failed res //action failed else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res end inline_for_extraction noextract let validate_dep_pair_with_refinement' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@(rename_let ("positionAfter" ^ name1))] let res = v1 ctxt error_handler_fn input input_length startPosition in let h1 = HST.get() in modifies_address_liveness_insensitive_unused_in h0 h1; if LPE.is_error res then begin res end else begin [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok res in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h1 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement_total_zero_parser' (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) (inv1 disj1 l1: _) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false) (requires ( let open LP in k1.parser_kind_high == Some 0 /\ k1.parser_kind_metadata == Some ParserKindMetadataTotal )) (ensures (fun _ -> True)) = fun ctxt error_handler_fn input input_length startPosition -> let h0 = HST.get () in LPC.parse_dtuple2_eq' #_ #_ (p1 `LPC.parse_filter` f) #_ #t2 p2 (I.get_remaining input h0); LPC.parse_filter_eq p1 f (I.get_remaining input h0); [@inline_let] let _ = LP.parser_kind_prop_equiv k1 p1 in begin LowStar.Comment.comment ("Validating field " ^ name1); [@(rename_let ("" ^ name1))] let field_value = r1 input startPosition in [@(rename_let (name1 ^ "ConstraintIsOk"))] let ok = f field_value in [@(rename_let ("positionAfter" ^ name1))] let res1 = LPE.check_constraint_ok ok startPosition in if LPE.is_error res1 then res1 else let h2 = HST.get() in // assert (B.modifies B.loc_none h1 h2); // assert (inv1' input.LPL.base h2); modifies_address_liveness_insensitive_unused_in h0 h2; // assert (loc_not_unused_in h2 `loc_includes` l1'); // assert (valid_pos (p1 `(LPC.parse_filter #k1 #t1)` f) h0 input (uint64_to_uint32 pos) (uint64_to_uint32 res)); let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h0 h15 in validate_drop (v2 field_value) ctxt error_handler_fn input input_length res1 end inline_for_extraction noextract let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #disj1 #l1 (v1:validate_with_action_t p1 inv1 disj1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #disj2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 disj2 l2 ar2)) = if p1_is_constant_size_without_actions `LP.bool_and` (k1.LP.parser_kind_high = Some 0) `LP.bool_and` (k1.LP.parser_kind_metadata = Some LP.ParserKindMetadataTotal) then validate_dep_pair_with_refinement_total_zero_parser' name1 inv1 disj1 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2 inline_for_extraction noextract let validate_filter (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); LPE.check_constraint_ok ok res end inline_for_extraction noextract let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #disj #l (v:validate_with_action_t p inv disj l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva #disja (#la:eloc) (a: t -> action inva disja la b bool) = fun ctxt error_handler_fn input input_length start_position -> [@inline_let] let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@(rename_let ("positionAfter" ^ name))] let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else begin LowStar.Comment.comment cr; [@(rename_let ("" ^ name))] let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^cf)); [@(rename_let (name ^ "ConstraintIsOk"))] let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res else LPE.set_validator_error_pos LPE.validator_error_constraint_failed res end
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowStar.Comment.fsti.checked", "LowStar.BufferOps.fst.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.List.fsti.checked", "LowParse.Spec.FLData.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "LowParse.Low.ListUpTo.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.FLData.fst.checked", "LowParse.Low.BoundedInt.fsti.checked", "LowParse.Low.Base.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Tactics.Typeclasses.fsti.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Tactics.fst.checked", "FStar.Seq.fst.checked", "FStar.PropositionalExtensionality.fst.checked", "FStar.PredicateExtensionality.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Math.Lemmas.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.FunctionalExtensionality.fsti.checked", "FStar.Classical.Sugar.fsti.checked", "FStar.Classical.fsti.checked", "EverParse3d.Util.fst.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "EverParse3d.CopyBuffer.fsti.checked", "EverParse3d.AppCtxt.fsti.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ { "abbrev": true, "full_module": "LowParse.Spec.Combinators", "short_module": "LPC" }, { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "FStar.FunctionalExtensionality", "short_module": "F" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "abbrev": true, "full_module": "EverParse3d.AppCtxt", "short_module": "AppCtxt" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "EverParse3d.InputStream.Base", "short_module": "I" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "B" }, { "abbrev": false, "full_module": "LowStar.BufferOps", "short_module": null }, { "abbrev": false, "full_module": "LowStar.Buffer", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.CopyBuffer", "short_module": "CP" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "EverParse3d.Prelude", "short_module": null }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "EverParse3d.Actions", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "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.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
name: Prims.string -> v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l true -> r: EverParse3d.Actions.Base.leaf_reader p -> a: (_: t -> EverParse3d.Actions.Base.action inva disja la b Prims.bool) -> EverParse3d.Actions.Base.validate_with_action_t p (EverParse3d.Actions.Base.conj_inv inv inva) (EverParse3d.Actions.Base.conj_disjointness disj disja) (EverParse3d.Actions.Base.eloc_union l la) false
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.action", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_error", "FStar.UInt64.t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_action_failed", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
let validate_with_dep_action (name: string) #nz (#k: parser_kind nz _) (#t: _) (#p: parser k t) #inv #disj #l (v: validate_with_action_t p inv disj l true) (r: leaf_reader p) (#b: bool) #inva #disja (#la: eloc) (a: (t -> action inva disja la b bool)) =
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos0 = start_position in let h = HST.get () in [@@ (rename_let ("positionAfter" ^ name)) ]let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else [@@ (rename_let ("" ^ name)) ]let field_value = r input pos0 in let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt error_handler_fn input input_length pos0 res then res else LPE.set_validator_error_pos LPE.validator_error_action_failed res
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to_payload
val serialize_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind{k.parser_kind_subkind <> Some ParserConsumesAll}) (#ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (stail: serializer ptail) (x: t) : Tot (serializer (parse_list_up_to_payload cond fuel k ptail x))
val serialize_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind{k.parser_kind_subkind <> Some ParserConsumesAll}) (#ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (stail: serializer ptail) (x: t) : Tot (serializer (parse_list_up_to_payload cond fuel k ptail x))
let serialize_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (#ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (stail: serializer ptail) (x: t) : Tot (serializer (parse_list_up_to_payload cond fuel k ptail x)) = if cond x then serialize_weaken (parse_list_up_to_payload_kind k) (serialize_ret UP_UNIT (fun _ -> ())) else serialize_weaken (parse_list_up_to_payload_kind k) stail
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 63, "end_line": 361, "start_col": 0, "start_line": 350 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy) let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed) )) = parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b let close_parse_list_up_to (b: bytes) : GTot (n: nat { Seq.length b < n }) = Seq.length b + 1 let parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to)) = close_by_fuel_correct (parse_list_up_to_kind k) (parse_list_up_to' cond p) close_parse_list_up_to (fun fuel b -> parse_list_up_to'_eq cond p (close_parse_list_up_to b) b; parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_ext cond p prf (close_parse_list_up_to b) fuel b ) (fun fuel -> parser_kind_prop_fuel_complete fuel (parse_list_up_to_kind k) (parse_list_up_to' cond p fuel) ) let parse_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_list_up_to_correct #k #t cond p prf; close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to let parse_list_up_to_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) (b: bytes) : Lemma (parse (parse_list_up_to cond p prf) b == ( match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to cond p prf) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = let fuel = close_parse_list_up_to b in parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; let b' = Seq.slice b consumed (Seq.length b) in let fuel' = close_parse_list_up_to b' in parse_list_up_to'_eq cond p fuel' b' ; parse_list_up_to_fuel_ext cond p prf (fuel - 1) fuel' b' end (* serializer *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> fuel: Prims.nat -> k: LowParse.Spec.Base.parser_kind { Mkparser_kind'?.parser_kind_subkind k <> FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserConsumesAll } -> stail: LowParse.Spec.Base.serializer ptail -> x: t -> LowParse.Spec.Base.serializer (LowParse.Spec.ListUpTo.parse_list_up_to_payload cond fuel k ptail x)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.nat", "LowParse.Spec.Base.parser_kind", "Prims.b2t", "Prims.op_disEquality", "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.ParserConsumesAll", "LowParse.Spec.Base.parser", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.Base.serializer", "LowParse.Spec.Combinators.serialize_weaken", "LowParse.Spec.Combinators.parse_ret_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind", "LowParse.Spec.Combinators.parse_ret", "LowParse.Spec.ListUpTo.UP_UNIT", "LowParse.Spec.Combinators.serialize_ret", "Prims.unit", "LowParse.Spec.ListUpTo.parse_list_up_to_payload" ]
[]
false
false
false
false
false
let serialize_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind{k.parser_kind_subkind <> Some ParserConsumesAll}) (#ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (stail: serializer ptail) (x: t) : Tot (serializer (parse_list_up_to_payload cond fuel k ptail x)) =
if cond x then serialize_weaken (parse_list_up_to_payload_kind k) (serialize_ret UP_UNIT (fun _ -> ())) else serialize_weaken (parse_list_up_to_payload_kind k) stail
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.synth_list_up_to_fuel_recip
val synth_list_up_to_fuel_recip (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond (fuel + 1)) : Tot (dtuple2 t (parse_list_up_to_payload_t cond fuel))
val synth_list_up_to_fuel_recip (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond (fuel + 1)) : Tot (dtuple2 t (parse_list_up_to_payload_t cond fuel))
let synth_list_up_to_fuel_recip (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond (fuel + 1)) : Tot (dtuple2 t (parse_list_up_to_payload_t cond fuel)) = let (l, z) = xy in match l with | [] -> (| z, UP_UNIT |) | x :: y -> (| x, ((y <: llist (refine_with_cond (negate_cond cond)) fuel), z) |)
{ "file_name": "src/lowparse/LowParse.Spec.ListUpTo.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 83, "end_line": 372, "start_col": 0, "start_line": 363 }
module LowParse.Spec.ListUpTo open LowParse.Spec.Base open LowParse.Spec.Fuel open LowParse.Spec.Combinators let llist (t: Type) (fuel: nat) : Tot Type = (l: list t { L.length l < fuel }) let parse_list_up_to_fuel_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Tot Type = (llist (refine_with_cond (negate_cond cond)) fuel) & refine_with_cond cond (* Universe-polymorphic unit type *) type up_unit : Type u#r = | UP_UNIT let parse_list_up_to_payload_t (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (x: t) : Tot Type = if cond x then up_unit else parse_list_up_to_fuel_t cond fuel let synth_list_up_to_fuel (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: dtuple2 t (parse_list_up_to_payload_t cond fuel)) : Tot (parse_list_up_to_fuel_t cond (fuel + 1)) = let (| x, yz |) = xy in if cond x then ([], x) else let (y, z) = (yz <: parse_list_up_to_fuel_t cond fuel) in (x :: y, z) let synth_list_up_to_injective (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_injective (synth_list_up_to_fuel cond fuel)) [SMTPat (synth_injective (synth_list_up_to_fuel cond fuel))] = () inline_for_extraction let parse_list_up_to_payload_kind (k: parser_kind) : Tot (k' : parser_kind {k' `is_weaker_than` k }) = { parser_kind_low = 0; parser_kind_high = None; parser_kind_subkind = k.parser_kind_subkind; parser_kind_metadata = None; } let parse_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (x: t) : Tot (parser (parse_list_up_to_payload_kind k) (parse_list_up_to_payload_t cond fuel x)) = if cond x then weaken (parse_list_up_to_payload_kind k) (parse_ret UP_UNIT) else weaken (parse_list_up_to_payload_kind k) ptail let rec parse_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (decreases fuel) = if fuel = 0 then fail_parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) else parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) `parse_synth` synth_list_up_to_fuel cond (fuel - 1) let parse_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to_fuel cond p fuel) b == ( if fuel = 0 then None else match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to_fuel cond p (fuel - 1)) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = if fuel = 0 then () else begin parse_synth_eq (parse_dtuple2 (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1)))) (synth_list_up_to_fuel cond (fuel - 1)) b; parse_dtuple2_eq' (weaken (parse_list_up_to_kind k) p) #(parse_list_up_to_payload_kind k) #(parse_list_up_to_payload_t cond (fuel - 1)) (parse_list_up_to_payload cond (fuel - 1) k (parse_list_up_to_fuel cond p (fuel - 1))) b end let rec parse_list_up_to_fuel_indep (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) (xy: parse_list_up_to_fuel_t cond fuel) (consumed: consumed_length b) (fuel' : nat { L.length (fst xy) < fuel' }) : Lemma (requires ( parse (parse_list_up_to_fuel cond p fuel) b == Some (xy, consumed) )) (ensures ( parse (parse_list_up_to_fuel cond p fuel') b == Some ((fst xy, snd xy), consumed) )) (decreases fuel) = assert (fuel > 0); assert (fuel' > 0); parse_list_up_to_fuel_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel' b; let Some (x, consumed_x) = parse p b in if cond x then () else let b' = Seq.slice b consumed_x (Seq.length b) in let Some (yz, consumed_yz) = parse (parse_list_up_to_fuel cond p (fuel - 1)) b' in parse_list_up_to_fuel_indep cond p (fuel - 1) b' yz consumed_yz (fuel' - 1) let rec parse_list_up_to_fuel_length (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel: nat) (b: bytes) : Lemma ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> True | Some (xy, consumed) -> L.length (fst xy) <= Seq.length b ) = parse_list_up_to_fuel_eq cond p fuel b; if fuel = 0 then () else match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_length cond p prf (fuel - 1) (Seq.slice b consumed (Seq.length b)) end let rec parse_list_up_to_fuel_ext (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) (fuel1 fuel2: nat) (b: bytes { Seq.length b < fuel1 /\ Seq.length b < fuel2 }) : Lemma (ensures ( match parse (parse_list_up_to_fuel cond p fuel1) b, parse (parse_list_up_to_fuel cond p fuel2) b with | None, None -> True | Some (xy1, consumed1), Some (xy2, consumed2) -> (fst xy1 <: list (refine_with_cond (negate_cond cond))) == (fst xy2 <: list (refine_with_cond (negate_cond cond))) /\ snd xy1 == snd xy2 /\ consumed1 == consumed2 | _ -> False )) (decreases fuel1) = parse_list_up_to_fuel_eq cond p fuel1 b; parse_list_up_to_fuel_eq cond p fuel2 b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)) end let synth_list_up_to' (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Tot (parse_list_up_to_t cond) = (fst xy, snd xy) let parse_list_up_to' (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_synth (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) let parse_list_up_to'_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (fuel: nat) (b: bytes) : Lemma (parse (parse_list_up_to' cond p fuel) b == ( match parse (parse_list_up_to_fuel cond p fuel) b with | None -> None | Some (xy, consumed) -> Some ((fst xy, snd xy), consumed) )) = parse_synth_eq (parse_list_up_to_fuel cond p fuel) (synth_list_up_to' cond fuel) b let close_parse_list_up_to (b: bytes) : GTot (n: nat { Seq.length b < n }) = Seq.length b + 1 let parse_list_up_to_correct (#k: parser_kind) (#t: Type u#r) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: ( (b: bytes) -> (x: t) -> (consumed: consumed_length b) -> Lemma (requires (parse p b == Some (x, consumed) /\ (~ (cond x)))) (ensures (consumed > 0)) )) : Lemma (parser_kind_prop (parse_list_up_to_kind k) (close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to)) = close_by_fuel_correct (parse_list_up_to_kind k) (parse_list_up_to' cond p) close_parse_list_up_to (fun fuel b -> parse_list_up_to'_eq cond p (close_parse_list_up_to b) b; parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_ext cond p prf (close_parse_list_up_to b) fuel b ) (fun fuel -> parser_kind_prop_fuel_complete fuel (parse_list_up_to_kind k) (parse_list_up_to' cond p fuel) ) let parse_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) : Tot (parser (parse_list_up_to_kind k) (parse_list_up_to_t cond)) = parse_list_up_to_correct #k #t cond p prf; close_by_fuel' (parse_list_up_to' cond p) close_parse_list_up_to let parse_list_up_to_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (p: parser k t { k.parser_kind_subkind <> Some ParserConsumesAll }) (prf: consumes_if_not_cond cond p) (b: bytes) : Lemma (parse (parse_list_up_to cond p prf) b == ( match parse p b with | None -> None | Some (x, consumed) -> if cond x then Some (([], x), consumed) else begin match parse (parse_list_up_to cond p prf) (Seq.slice b consumed (Seq.length b)) with | None -> None | Some ((y, z), consumed') -> Some ((x::y, z), consumed + consumed') end )) = let fuel = close_parse_list_up_to b in parse_list_up_to'_eq cond p fuel b; parse_list_up_to_fuel_eq cond p fuel b; match parse p b with | None -> () | Some (x, consumed) -> if cond x then () else begin prf b x consumed; let b' = Seq.slice b consumed (Seq.length b) in let fuel' = close_parse_list_up_to b' in parse_list_up_to'_eq cond p fuel' b' ; parse_list_up_to_fuel_ext cond p prf (fuel - 1) fuel' b' end (* serializer *) let serialize_list_up_to_payload (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (k: parser_kind { k.parser_kind_subkind <> Some ParserConsumesAll }) (#ptail: parser (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel)) (stail: serializer ptail) (x: t) : Tot (serializer (parse_list_up_to_payload cond fuel k ptail x)) = if cond x then serialize_weaken (parse_list_up_to_payload_kind k) (serialize_ret UP_UNIT (fun _ -> ())) else serialize_weaken (parse_list_up_to_payload_kind k) stail
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "LowParse.Spec.Seq.fst.checked", "LowParse.Spec.Fuel.fst.checked", "LowParse.Spec.Combinators.fsti.checked", "LowParse.Spec.Base.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": true, "source_file": "LowParse.Spec.ListUpTo.fst" }
[ { "abbrev": false, "full_module": "LowParse.Spec.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Fuel", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "Seq" }, { "abbrev": true, "full_module": "FStar.List.Tot", "short_module": "L" }, { "abbrev": false, "full_module": "LowParse.Spec.Base", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
cond: (_: t -> Prims.bool) -> fuel: Prims.nat -> xy: LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond (fuel + 1) -> Prims.dtuple2 t (LowParse.Spec.ListUpTo.parse_list_up_to_payload_t cond fuel)
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.nat", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "Prims.op_Addition", "LowParse.Spec.ListUpTo.llist", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "Prims.Mkdtuple2", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "LowParse.Spec.ListUpTo.UP_UNIT", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "Prims.dtuple2" ]
[]
false
false
false
false
false
let synth_list_up_to_fuel_recip (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) (xy: parse_list_up_to_fuel_t cond (fuel + 1)) : Tot (dtuple2 t (parse_list_up_to_payload_t cond fuel)) =
let l, z = xy in match l with | [] -> (| z, UP_UNIT |) | x :: y -> (| x, ((y <: llist (refine_with_cond (negate_cond cond)) fuel), z) |)
false