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.validate_dep_pair
val validate_dep_pair (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) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:t1 -> Type) (#[@@@erasable] p2:(x:t1 -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
val validate_dep_pair (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) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:t1 -> Type) (#[@@@erasable] p2:(x:t1 -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (conj_disjointness disj1 disj2) (l1 `eloc_union` l2) false
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
{ "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": 474, "start_col": 0, "start_line": 452 }
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
{ "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 true -> r1: EverParse3d.Actions.Base.leaf_reader p1 -> v2: (x: t1 -> 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 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.Actions.Base.leaf_reader", "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.parse_dtuple2_eq", "EverParse3d.InputStream.Base.get_remaining" ]
[]
false
false
false
false
false
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 pos1 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
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to'
val serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) : Tot (bare_serializer (parse_list_up_to_t cond))
val serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) : Tot (bare_serializer (parse_list_up_to_t cond))
let serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (bare_serializer (parse_list_up_to_t cond)) = fun xy -> serialize (serialize_list_up_to_fuel cond s (L.length (fst xy) + 1)) (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": 87, "end_line": 459, "start_col": 0, "start_line": 451 }
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 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) |) let synth_list_up_to_fuel_inverse (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel)) [SMTPat (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel))] = () let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) = if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () let serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma (serialize (serialize_list_up_to_fuel cond s fuel) xy `Seq.equal` ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z) )) = serialize_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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () xy; serialize_dtuple2_eq' (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) (synth_list_up_to_fuel_recip cond (fuel - 1) 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) -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> LowParse.Spec.Base.bare_serializer (LowParse.Spec.ListUpTo.parse_list_up_to_t cond)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.Base.serialize", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "Prims.op_Addition", "FStar.List.Tot.Base.length", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "Prims.list", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "LowParse.Spec.ListUpTo.serialize_list_up_to_fuel", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.ListUpTo.llist", "FStar.Pervasives.Native.snd", "LowParse.Bytes.bytes", "LowParse.Spec.Base.bare_serializer" ]
[]
false
false
false
false
false
let serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) : Tot (bare_serializer (parse_list_up_to_t cond)) =
fun xy -> serialize (serialize_list_up_to_fuel cond s (L.length (fst xy) + 1)) (fst xy, snd xy)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_weaken
val action_weaken (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#b:_) (#a:_) (act:action inv disj l b a) (#[@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) (#[@@@erasable] disj':disjointness_pre { disj' `imp_disjointness` disj }) (#l':eloc{l' `eloc_includes` l}) : action inv' disj' l' b a
val action_weaken (#[@@@erasable] inv:slice_inv) (#[@@@erasable] disj:disjointness_pre) (#[@@@erasable] l:eloc) (#b:_) (#a:_) (act:action inv disj l b a) (#[@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) (#[@@@erasable] disj':disjointness_pre { disj' `imp_disjointness` disj }) (#l':eloc{l' `eloc_includes` l}) : action inv' disj' l' b a
let action_weaken #inv #disj #l #b #a act #inv' #disj' #l' = act
{ "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": 64, "end_line": 1836, "start_col": 0, "start_line": 1836 }
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
{ "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
act: EverParse3d.Actions.Base.action inv disj l b a -> EverParse3d.Actions.Base.action inv' disj' l' b a
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.action", "EverParse3d.Actions.Base.inv_implies", "EverParse3d.Actions.Base.imp_disjointness", "EverParse3d.Actions.Base.eloc_includes" ]
[]
false
false
false
false
false
let action_weaken #inv #disj #l #b #a act #inv' #disj' #l' =
act
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_field_pos_64
val action_field_pos_64 : action true_inv disjointness_trivial eloc_none false U64.t
val action_field_pos_64 : action true_inv disjointness_trivial eloc_none false U64.t
let action_field_pos_64 = fun _ _ _ _ pos _ -> 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": 26, "end_line": 1798, "start_col": 0, "start_line": 1797 }
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
{ "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.action EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false FStar.UInt64.t
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 action_field_pos_64 =
fun _ _ _ _ pos _ -> pos
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 }) (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 ))
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 }) (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 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
{ "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": 7, "end_line": 346, "start_col": 0, "start_line": 313 }
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
{ "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 -> b: LowParse.Bytes.bytes -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to cond p prf) b == (match LowParse.Spec.Base.parse p b with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed) -> (match cond x with | true -> FStar.Pervasives.Native.Some (([], x), consumed) | _ -> (match LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to cond p prf) (FStar.Seq.Base.slice b consumed (FStar.Seq.Base.length b)) with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y z) consumed') -> FStar.Pervasives.Native.Some ((x :: y, z), consumed + consumed')) <: FStar.Pervasives.Native.option (LowParse.Spec.ListUpTo.parse_list_up_to_t cond * LowParse.Spec.Base.consumed_length b)) <: FStar.Pervasives.Native.option (LowParse.Spec.ListUpTo.parse_list_up_to_t cond * LowParse.Spec.Base.consumed_length b)))
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.Spec.ListUpTo.consumes_if_not_cond", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_ext", "Prims.op_Subtraction", "Prims.unit", "LowParse.Spec.ListUpTo.parse_list_up_to'_eq", "Prims.nat", "Prims.op_LessThan", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.ListUpTo.close_parse_list_up_to", "FStar.Seq.Base.seq", "FStar.Seq.Base.slice", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_eq", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "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", "Prims.Nil", "Prims.Cons", "Prims.op_Addition", "FStar.Pervasives.pattern" ]
[]
false
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}) (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 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'))) =
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 (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')
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to_correct
val serialize_list_up_to_correct (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (xy: parse_list_up_to_t cond) : Lemma (let sq = serialize_list_up_to' cond s xy in parse (parse_list_up_to cond p prf) sq == Some (xy, Seq.length sq))
val serialize_list_up_to_correct (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (xy: parse_list_up_to_t cond) : Lemma (let sq = serialize_list_up_to' cond s xy in parse (parse_list_up_to cond p prf) sq == Some (xy, Seq.length sq))
let serialize_list_up_to_correct (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (xy: parse_list_up_to_t cond) : Lemma ( let sq = serialize_list_up_to' cond s xy in parse (parse_list_up_to cond p prf) sq == Some (xy, Seq.length sq) ) = let sq = serialize_list_up_to' cond s xy in let fuel' = close_parse_list_up_to sq in let fuel = L.length (fst xy) + 1 in parse_list_up_to'_eq cond p fuel' sq; parse_list_up_to_fuel_length cond p prf fuel sq; parse_list_up_to_fuel_indep cond p fuel sq (fst xy, snd xy) (Seq.length sq) 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": 83, "end_line": 479, "start_col": 0, "start_line": 461 }
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 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) |) let synth_list_up_to_fuel_inverse (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel)) [SMTPat (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel))] = () let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) = if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () let serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma (serialize (serialize_list_up_to_fuel cond s fuel) xy `Seq.equal` ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z) )) = serialize_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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () xy; serialize_dtuple2_eq' (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) (synth_list_up_to_fuel_recip cond (fuel - 1) xy) let serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (bare_serializer (parse_list_up_to_t cond)) = fun xy -> serialize (serialize_list_up_to_fuel cond s (L.length (fst xy) + 1)) (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) -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond cond p -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> xy: LowParse.Spec.ListUpTo.parse_list_up_to_t cond -> FStar.Pervasives.Lemma (ensures (let sq = LowParse.Spec.ListUpTo.serialize_list_up_to' cond s xy in LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to cond p prf) sq == FStar.Pervasives.Native.Some (xy, FStar.Seq.Base.length sq)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "LowParse.Spec.ListUpTo.consumes_if_not_cond", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_indep", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.ListUpTo.llist", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "Prims.list", "FStar.Pervasives.Native.snd", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.unit", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_length", "LowParse.Spec.ListUpTo.parse_list_up_to'_eq", "Prims.int", "Prims.op_Addition", "FStar.List.Tot.Base.length", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Spec.ListUpTo.close_parse_list_up_to", "LowParse.Bytes.bytes", "LowParse.Spec.ListUpTo.serialize_list_up_to'", "Prims.l_True", "Prims.squash", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.ListUpTo.parse_list_up_to", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let serialize_list_up_to_correct (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (xy: parse_list_up_to_t cond) : Lemma (let sq = serialize_list_up_to' cond s xy in parse (parse_list_up_to cond p prf) sq == Some (xy, Seq.length sq)) =
let sq = serialize_list_up_to' cond s xy in let fuel' = close_parse_list_up_to sq in let fuel = L.length (fst xy) + 1 in parse_list_up_to'_eq cond p fuel' sq; parse_list_up_to_fuel_length cond p prf fuel sq; parse_list_up_to_fuel_indep cond p fuel sq (fst xy, snd xy) (Seq.length sq) fuel'
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_assignment
val action_assignment (#a:_) (x:bpointer a) (v:a) : action (ptr_inv x) disjointness_trivial (ptr_loc x) false unit
val action_assignment (#a:_) (x:bpointer a) (v:a) : action (ptr_inv x) disjointness_trivial (ptr_loc x) false unit
let action_assignment (#a:_) (x:B.pointer a) (v:a) = fun _ _ _ _ _ _ -> ptr_inv_elim x; x *= 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": 10, "end_line": 1832, "start_col": 0, "start_line": 1828 }
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
{ "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
x: EverParse3d.Actions.Base.bpointer a -> v: a -> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.ptr_inv x) EverParse3d.Actions.Base.disjointness_trivial (EverParse3d.Actions.Base.ptr_loc x) false Prims.unit
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.pointer", "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", "LowStar.BufferOps.op_Star_Equals", "LowStar.Buffer.trivial_preorder", "Prims.unit", "EverParse3d.Actions.Base.ptr_inv_elim" ]
[]
false
false
false
false
false
let action_assignment (#a: _) (x: B.pointer a) (v: a) =
fun _ _ _ _ _ _ -> ptr_inv_elim x; x *= v
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_deref
val action_deref (#a:_) (x:bpointer a) : action (ptr_inv x) disjointness_trivial eloc_none false a
val action_deref (#a:_) (x:bpointer a) : action (ptr_inv x) disjointness_trivial eloc_none false a
let action_deref (#a:_) (x:B.pointer a) = fun _ _ _ _ _ _ -> ptr_inv_elim x; !*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": 7, "end_line": 1824, "start_col": 0, "start_line": 1820 }
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
{ "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
x: EverParse3d.Actions.Base.bpointer a -> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.ptr_inv x) EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false a
Prims.Tot
[ "total" ]
[]
[ "LowStar.Buffer.pointer", "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", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "Prims.unit", "EverParse3d.Actions.Base.ptr_inv_elim" ]
[]
false
false
false
false
false
let action_deref (#a: _) (x: B.pointer a) =
fun _ _ _ _ _ _ -> ptr_inv_elim x; !*x
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to
val serialize_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (serializer (parse_list_up_to cond p prf))
val serialize_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (serializer (parse_list_up_to cond p prf))
let serialize_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (serializer (parse_list_up_to cond p prf)) = Classical.forall_intro (serialize_list_up_to_correct cond prf s); serialize_list_up_to' cond s
{ "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": 30, "end_line": 490, "start_col": 0, "start_line": 481 }
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 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) |) let synth_list_up_to_fuel_inverse (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel)) [SMTPat (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel))] = () let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) = if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () let serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma (serialize (serialize_list_up_to_fuel cond s fuel) xy `Seq.equal` ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z) )) = serialize_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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () xy; serialize_dtuple2_eq' (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) (synth_list_up_to_fuel_recip cond (fuel - 1) xy) let serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (bare_serializer (parse_list_up_to_t cond)) = fun xy -> serialize (serialize_list_up_to_fuel cond s (L.length (fst xy) + 1)) (fst xy, snd xy) let serialize_list_up_to_correct (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (xy: parse_list_up_to_t cond) : Lemma ( let sq = serialize_list_up_to' cond s xy in parse (parse_list_up_to cond p prf) sq == Some (xy, Seq.length sq) ) = let sq = serialize_list_up_to' cond s xy in let fuel' = close_parse_list_up_to sq in let fuel = L.length (fst xy) + 1 in parse_list_up_to'_eq cond p fuel' sq; parse_list_up_to_fuel_length cond p prf fuel sq; parse_list_up_to_fuel_indep cond p fuel sq (fst xy, snd xy) (Seq.length sq) 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) -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond cond p -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> LowParse.Spec.Base.serializer (LowParse.Spec.ListUpTo.parse_list_up_to cond p prf)
Prims.Tot
[ "total" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "LowParse.Spec.ListUpTo.consumes_if_not_cond", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.ListUpTo.serialize_list_up_to'", "Prims.unit", "FStar.Classical.forall_intro", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "LowParse.Spec.ListUpTo.parse_list_up_to", "FStar.Pervasives.Native.Mktuple2", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.ListUpTo.serialize_list_up_to_correct", "LowParse.Spec.ListUpTo.parse_list_up_to_kind" ]
[]
false
false
false
false
false
let serialize_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) : Tot (serializer (parse_list_up_to cond p prf)) =
Classical.forall_intro (serialize_list_up_to_correct cond prf s); serialize_list_up_to' cond s
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_fuel_eq
val 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 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')))
val 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 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')))
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
{ "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": 131, "start_col": 0, "start_line": 93 }
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)
{ "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_fuel cond p fuel) b == (match fuel = 0 with | true -> FStar.Pervasives.Native.None | _ -> (match LowParse.Spec.Base.parse p b with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ x consumed) -> (match cond x with | true -> FStar.Pervasives.Native.Some (([], x), consumed) | _ -> (match LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p (fuel - 1)) (FStar.Seq.Base.slice b consumed (FStar.Seq.Base.length b)) with | FStar.Pervasives.Native.None #_ -> FStar.Pervasives.Native.None | FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ y z) consumed') -> FStar.Pervasives.Native.Some ((x :: y, z), consumed + consumed')) <: FStar.Pervasives.Native.option (LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel * LowParse.Spec.Base.consumed_length b)) <: FStar.Pervasives.Native.option (LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel * LowParse.Spec.Base.consumed_length b)) <: FStar.Pervasives.Native.option (LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel * LowParse.Spec.Base.consumed_length b)))
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", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.parse_dtuple2_eq'", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.Base.weaken", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "Prims.op_Subtraction", "LowParse.Spec.ListUpTo.parse_list_up_to_payload", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "Prims.unit", "LowParse.Spec.Combinators.parse_synth_eq", "LowParse.Spec.Combinators.and_then_kind", "Prims.dtuple2", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "Prims.op_Addition", "LowParse.Spec.Combinators.parse_dtuple2", "LowParse.Spec.ListUpTo.synth_list_up_to_fuel", "Prims.l_True", "Prims.squash", "Prims.eq2", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "FStar.Pervasives.Native.None", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.ListUpTo.llist", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "Prims.Nil", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "FStar.Seq.Base.length", "Prims.Cons", "FStar.Pervasives.pattern" ]
[]
false
false
true
false
false
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 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'))) =
if fuel = 0 then () else (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)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_abort
val action_abort : action true_inv disjointness_trivial eloc_none false bool
val action_abort : action true_inv disjointness_trivial eloc_none false bool
let action_abort = fun _ _ _ _ _ _ -> false
{ "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": 26, "end_line": 1793, "start_col": 0, "start_line": 1792 }
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
{ "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.action EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial EverParse3d.Actions.Base.eloc_none false Prims.bool
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", "Prims.bool" ]
[]
false
false
false
false
false
let action_abort =
fun _ _ _ _ _ _ -> false
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.mk_external_action
val mk_external_action (#l:eloc) ($f: external_action l) : action true_inv disjointness_trivial l false unit
val mk_external_action (#l:eloc) ($f: external_action l) : action true_inv disjointness_trivial l false unit
let mk_external_action #_ f = fun _ _ _ _ _ _ -> f ()
{ "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": 1843, "start_col": 0, "start_line": 1843 }
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 let external_action l = unit -> Stack unit (fun _ -> True) (fun h0 _ h1 -> B.modifies l h0 h1) 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": "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
$f: EverParse3d.Actions.Base.external_action l -> EverParse3d.Actions.Base.action EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.disjointness_trivial l false Prims.unit
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.external_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" ]
[]
false
false
false
false
false
let mk_external_action #_ f =
fun _ _ _ _ _ _ -> f ()
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to_fuel
val serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel)
val serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel)
let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) = if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip 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": 8, "end_line": 409, "start_col": 0, "start_line": 383 }
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 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) |) let synth_list_up_to_fuel_inverse (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel)) [SMTPat (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip 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) -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> fuel: Prims.nat -> Prims.Tot (LowParse.Spec.Base.serializer (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel))
Prims.Tot
[ "total", "" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "Prims.op_Equality", "Prims.int", "LowParse.Spec.Combinators.fail_serializer", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "Prims.unit", "LowParse.Spec.Combinators.serialize_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", "LowParse.Spec.Combinators.serialize_dtuple2", "LowParse.Spec.Combinators.serialize_weaken", "LowParse.Spec.ListUpTo.serialize_list_up_to_payload", "LowParse.Spec.ListUpTo.serialize_list_up_to_fuel", "LowParse.Spec.ListUpTo.synth_list_up_to_fuel_recip" ]
[ "recursion" ]
false
false
false
false
false
let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) =
if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) ()
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.copy_buffer_inv
val copy_buffer_inv (x:CP.copy_buffer_t) : slice_inv
val copy_buffer_inv (x:CP.copy_buffer_t) : slice_inv
let copy_buffer_inv (x:CP.copy_buffer_t) : slice_inv = CP.properties x; F.on HS.mem #prop (CP.inv 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": 30, "end_line": 1848, "start_col": 0, "start_line": 1845 }
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 let external_action l = unit -> Stack unit (fun _ -> True) (fun h0 _ h1 -> B.modifies l h0 h1) noextract inline_for_extraction let mk_external_action #_ f = fun _ _ _ _ _ _ -> f ()
{ "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
x: EverParse3d.CopyBuffer.copy_buffer_t -> EverParse3d.Actions.Base.slice_inv
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.CopyBuffer.copy_buffer_t", "FStar.FunctionalExtensionality.on", "FStar.Monotonic.HyperStack.mem", "Prims.prop", "EverParse3d.CopyBuffer.inv", "Prims.unit", "EverParse3d.CopyBuffer.properties", "EverParse3d.Actions.Base.slice_inv" ]
[]
false
false
false
true
false
let copy_buffer_inv (x: CP.copy_buffer_t) : slice_inv =
CP.properties x; F.on HS.mem #prop (CP.inv x)
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.parse_list_up_to_fuel_ext
val 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)
val 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)
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
{ "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": 7, "end_line": 230, "start_col": 0, "start_line": 197 }
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
{ "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)) -> fuel1: Prims.nat -> fuel2: Prims.nat -> b: LowParse.Bytes.bytes{FStar.Seq.Base.length b < fuel1 /\ FStar.Seq.Base.length b < fuel2} -> FStar.Pervasives.Lemma (ensures ((match LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel1) b, LowParse.Spec.Base.parse (LowParse.Spec.ListUpTo.parse_list_up_to_fuel cond p fuel2) b with | FStar.Pervasives.Native.Mktuple2 #_ #_ (FStar.Pervasives.Native.None #_) (FStar.Pervasives.Native.None #_) -> Prims.l_True | FStar.Pervasives.Native.Mktuple2 #_ #_ (FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ xy1 consumed1)) (FStar.Pervasives.Native.Some #_ (FStar.Pervasives.Native.Mktuple2 #_ #_ xy2 consumed2)) -> FStar.Pervasives.Native.fst xy1 == FStar.Pervasives.Native.fst xy2 /\ FStar.Pervasives.Native.snd xy1 == FStar.Pervasives.Native.snd xy2 /\ consumed1 == consumed2 | _ -> Prims.l_False) <: Type0)) (decreases fuel1)
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_LessThan", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_ext", "Prims.op_Subtraction", "FStar.Seq.Base.slice", "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.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.l_False" ]
[ "recursion" ]
false
false
true
false
false
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 (prf b x consumed; parse_list_up_to_fuel_ext cond p prf (fuel1 - 1) (fuel2 - 1) (Seq.slice b consumed (Seq.length b)))
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.copy_buffer_loc
val copy_buffer_loc (x:CP.copy_buffer_t) : eloc
val copy_buffer_loc (x:CP.copy_buffer_t) : eloc
let copy_buffer_loc (x:CP.copy_buffer_t) : eloc = CP.loc_of 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": 13, "end_line": 1851, "start_col": 0, "start_line": 1849 }
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 let external_action l = unit -> Stack unit (fun _ -> True) (fun h0 _ h1 -> B.modifies l h0 h1) noextract inline_for_extraction let mk_external_action #_ f = fun _ _ _ _ _ _ -> f () let copy_buffer_inv (x:CP.copy_buffer_t) : slice_inv = CP.properties x;
{ "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
x: EverParse3d.CopyBuffer.copy_buffer_t -> EverParse3d.Actions.Base.eloc
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.CopyBuffer.copy_buffer_t", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "EverParse3d.CopyBuffer.loc_of", "EverParse3d.Actions.Base.eloc" ]
[]
false
false
false
true
false
let copy_buffer_loc (x: CP.copy_buffer_t) : eloc =
CP.loc_of x
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_seq
val action_seq (#[@@@erasable] invf:slice_inv) (#[@@@erasable] disjf:disjointness_pre) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action invf disjf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] disjg:disjointness_pre) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: action invg disjg lg bg b) : action (conj_inv invf invg) (conj_disjointness disjf disjg) (eloc_union lf lg) (bf || bg) b
val action_seq (#[@@@erasable] invf:slice_inv) (#[@@@erasable] disjf:disjointness_pre) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action invf disjf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] disjg:disjointness_pre) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: action invg disjg lg bg b) : action (conj_inv invf invg) (conj_disjointness disjf disjg) (eloc_union lf lg) (bf || bg) b
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
{ "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": 1775, "start_col": 0, "start_line": 1765 }
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
{ "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
f: EverParse3d.Actions.Base.action invf disjf lf bf a -> g: EverParse3d.Actions.Base.action invg disjg lg bg b -> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.conj_inv invf invg) (EverParse3d.Actions.Base.conj_disjointness disjf disjg) (EverParse3d.Actions.Base.eloc_union lf lg) (bf || bg) b
Prims.Tot
[ "total" ]
[]
[ "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", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
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
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to_fuel_eq
val serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma ((serialize (serialize_list_up_to_fuel cond s fuel) xy) `Seq.equal` (let l, z = xy in match l with | [] -> serialize s z | x :: y -> (serialize s x) `Seq.append` (serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z))))
val serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma ((serialize (serialize_list_up_to_fuel cond s fuel) xy) `Seq.equal` (let l, z = xy in match l with | [] -> serialize s z | x :: y -> (serialize s x) `Seq.append` (serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z))))
let serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma (serialize (serialize_list_up_to_fuel cond s fuel) xy `Seq.equal` ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z) )) = serialize_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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () xy; serialize_dtuple2_eq' (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) (synth_list_up_to_fuel_recip cond (fuel - 1) 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": 52, "end_line": 449, "start_col": 0, "start_line": 411 }
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 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) |) let synth_list_up_to_fuel_inverse (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel)) [SMTPat (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel))] = () let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) = if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (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) -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> fuel: Prims.nat -> xy: LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t cond fuel -> FStar.Pervasives.Lemma (ensures FStar.Seq.Base.equal (LowParse.Spec.Base.serialize (LowParse.Spec.ListUpTo.serialize_list_up_to_fuel cond s fuel) xy) (let _ = xy in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l z = _ in (match l with | Prims.Nil #_ -> LowParse.Spec.Base.serialize s z | Prims.Cons #_ x y -> FStar.Seq.Base.append (LowParse.Spec.Base.serialize s x) (LowParse.Spec.Base.serialize (LowParse.Spec.ListUpTo.serialize_list_up_to_fuel cond s (fuel - 1)) (y, z))) <: FStar.Seq.Base.seq LowParse.Bytes.byte) <: FStar.Seq.Base.seq LowParse.Bytes.byte))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel_t", "LowParse.Spec.Combinators.serialize_dtuple2_eq'", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.Base.weaken", "LowParse.Spec.Combinators.serialize_weaken", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_payload_t", "Prims.op_Subtraction", "LowParse.Spec.ListUpTo.parse_list_up_to_payload", "LowParse.Spec.ListUpTo.parse_list_up_to_fuel", "LowParse.Spec.ListUpTo.serialize_list_up_to_payload", "LowParse.Spec.ListUpTo.serialize_list_up_to_fuel", "LowParse.Spec.ListUpTo.synth_list_up_to_fuel_recip", "Prims.unit", "LowParse.Spec.Combinators.serialize_synth_eq", "LowParse.Spec.Combinators.and_then_kind", "Prims.dtuple2", "Prims.op_Addition", "LowParse.Spec.Combinators.parse_dtuple2", "LowParse.Spec.ListUpTo.synth_list_up_to_fuel", "LowParse.Spec.Combinators.serialize_dtuple2", "Prims.l_True", "Prims.squash", "FStar.Seq.Base.equal", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Spec.ListUpTo.llist", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "Prims.list", "FStar.Seq.Base.append", "FStar.Pervasives.Native.Mktuple2", "FStar.Seq.Base.seq", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma ((serialize (serialize_list_up_to_fuel cond s fuel) xy) `Seq.equal` (let l, z = xy in match l with | [] -> serialize s z | x :: y -> (serialize s x) `Seq.append` (serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z)))) =
serialize_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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) ) (synth_list_up_to_fuel_recip cond (fuel - 1)) () xy; serialize_dtuple2_eq' (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) (synth_list_up_to_fuel_recip cond (fuel - 1) xy)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_fldata
val 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
val 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
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
{ "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": 1127, "start_col": 0, "start_line": 1090 }
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
{ "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", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 16, "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 -> 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'", "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", "EverParse3d.ErrorCode.is_error", "EverParse3d.ErrorCode.validator_error_unexpected_padding", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.InputStream.Base.has", "FStar.UInt64.__uint_to_t", "EverParse3d.InputStream.Base.is_prefix_of_prop", "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", "EverParse3d.InputStream.Base.__proj__Mkinput_stream_inst__item__tlen", "EverParse3d.InputStream.Base.truncate_len", "FStar.Int.Cast.uint32_to_uint64", "EverParse3d.InputStream.Base.truncate", "LowParse.Spec.FLData.parse_fldata_kind", "LowParse.Spec.FLData.parse_fldata" ]
[]
false
false
false
false
false
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 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 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
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_bind
val action_bind (name: string) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] disjf:disjointness_pre) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action invf disjf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] disjg:disjointness_pre) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: (a -> action invg disjg lg bg b)) : action (conj_inv invf invg) (conj_disjointness disjf disjg) (eloc_union lf lg) (bf || bg) b
val action_bind (name: string) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] disjf:disjointness_pre) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action invf disjf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] disjg:disjointness_pre) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: (a -> action invg disjg lg bg b)) : action (conj_inv invf invg) (conj_disjointness disjf disjg) (eloc_union lf lg) (bf || bg) b
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
{ "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": 1761, "start_col": 0, "start_line": 1749 }
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
{ "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
name: Prims.string -> f: EverParse3d.Actions.Base.action invf disjf lf bf a -> g: (_: a -> EverParse3d.Actions.Base.action invg disjg lg bg b) -> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.conj_inv invf invg) (EverParse3d.Actions.Base.conj_disjointness disjf disjg) (EverParse3d.Actions.Base.eloc_union lf lg) (bf || bg) b
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", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
false
false
false
false
false
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
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.action_ite
val action_ite (#[@@@erasable] invf:slice_inv) (#[@@@erasable] disjf:disjointness_pre) (#[@@@erasable] lf:eloc) (guard:bool) (#bf:_) (#a:Type) (then_: squash guard -> action invf disjf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] disjg:disjointness_pre) (#[@@@erasable] lg:eloc) (#bg:_) (else_: squash (not guard) -> action invg disjg lg bg a) : action (conj_inv invf invg) (conj_disjointness disjf disjg) (eloc_union lf lg) (bf || bg) a
val action_ite (#[@@@erasable] invf:slice_inv) (#[@@@erasable] disjf:disjointness_pre) (#[@@@erasable] lf:eloc) (guard:bool) (#bf:_) (#a:Type) (then_: squash guard -> action invf disjf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] disjg:disjointness_pre) (#[@@@erasable] lg:eloc) (#bg:_) (else_: squash (not guard) -> action invg disjg lg bg a) : action (conj_inv invf invg) (conj_disjointness disjf disjg) (eloc_union lf lg) (bf || bg) a
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
{ "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": 67, "end_line": 1788, "start_col": 0, "start_line": 1779 }
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
{ "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
guard: Prims.bool -> then_: (_: Prims.squash guard -> EverParse3d.Actions.Base.action invf disjf lf bf a) -> else_: (_: Prims.squash (Prims.op_Negation guard) -> EverParse3d.Actions.Base.action invg disjg lg bg a) -> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.conj_inv invf invg) (EverParse3d.Actions.Base.conj_disjointness disjf disjg) (EverParse3d.Actions.Base.eloc_union lf lg) (bf || bg) a
Prims.Tot
[ "total" ]
[]
[ "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "Prims.bool", "Prims.squash", "Prims.b2t", "EverParse3d.Actions.Base.action", "Prims.op_Negation", "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_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
false
Steel.SpinLock.fst
Steel.SpinLock.acquire_core
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))
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
{ "file_name": "lib/steel/Steel.SpinLock.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 12, "end_line": 77, "start_col": 0, "start_line": 66 }
(* 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))
{ "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", "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
r: Steel.Reference.ref Prims.bool -> i: Steel.Effect.Common.inv (Steel.SpinLock.lockinv p r) -> Steel.Effect.Atomic.SteelAtomicT Prims.bool
Steel.Effect.Atomic.SteelAtomicT
[]
[]
[ "Steel.Effect.Common.vprop", "Steel.Memory.inames", "Steel.Reference.ref", "Prims.bool", "Steel.Effect.Common.inv", "Steel.SpinLock.lockinv", "Steel.Effect.Atomic.return", "Steel.Effect.Common.VStar", "Steel.Effect.Common.emp", "Prims.unit", "Steel.SpinLock.intro_lockinv_locked", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.SpinLock.locked", "FStar.Ghost.reveal", "Steel.Memory.mem", "Prims.l_iff", "Prims.b2t", "Prims.eq2", "Steel.SpinLock.available", "Steel.Reference.cas_pt_bool", "FStar.Ghost.erased", "Steel.Effect.Atomic.witness_exists", "Steel.Effect.Common.star" ]
[]
false
true
false
false
false
let acquire_core #p #u r i =
let ghost = witness_exists () in let res = cas_pt_bool r ghost available locked in 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
false
Hacl.P256.PrecompTable.fst
Hacl.P256.PrecompTable.proj_g_pow2_64
val proj_g_pow2_64:S.proj_point
val proj_g_pow2_64:S.proj_point
let proj_g_pow2_64 : S.proj_point = [@inline_let] let rX : S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in [@inline_let] let rY : S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in [@inline_let] let rZ : S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in (rX, rY, rZ)
{ "file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 14, "end_line": 44, "start_col": 0, "start_line": 37 }
module Hacl.P256.PrecompTable open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module SPT = Hacl.Spec.PrecompBaseTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module SPTK = Hacl.Spec.P256.PrecompTable module S = Spec.P256 module SL = Spec.P256.Lemmas open Hacl.Impl.P256.Point include Hacl.Impl.P256.Group #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let proj_point_to_list p = SPTK.proj_point_to_list_lemma p; SPTK.proj_point_to_list p let lemma_refl x = SPTK.proj_point_to_list_lemma x //-----------------
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.PrecompTable.fsti.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Group.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.P256.PrecompTable.fst" }
[ { "abbrev": false, "full_module": "Hacl.Impl.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.PrecompTable", "short_module": "SPTK" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Spec.P256.PointOps.proj_point
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.Native.Mktuple3", "Prims.nat", "Spec.P256.PointOps.felem" ]
[]
false
false
false
true
false
let proj_g_pow2_64:S.proj_point =
[@@ inline_let ]let rX:S.felem = 0x000931f4ae428a4ad81ee0aa89cf5247ce85d4dd696c61b4bb9d4761e57b7fbe in [@@ inline_let ]let rY:S.felem = 0x7e88e5e6a142d5c2269f21a158e82ab2c79fcecb26e397b96fd5b9fbcd0a69a5 in [@@ inline_let ]let rZ:S.felem = 0x02626dc2dd5e06cd19de5e6afb6c5dbdd3e41dc1472e7b8ef11eb0662e41c44b in (rX, rY, rZ)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_dep_pair_with_refinement_total_zero_parser'
val 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))
val 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))
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
{ "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": 11, "end_line": 729, "start_col": 0, "start_line": 683 }
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
{ "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
name1: Prims.string -> inv1: EverParse3d.Actions.Base.slice_inv -> disj1: EverParse3d.Actions.Base.disjointness_pre -> l1: EverParse3d.Actions.Base.eloc -> 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 ar2) -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (LowParse.Spec.Combinators.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.Pure
[]
[]
[ "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.leaf_reader", "EverParse3d.Kinds.weak_kind", "EverParse3d.Prelude.refine", "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_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", "EverParse3d.ErrorCode.check_constraint_ok", "LowStar.Comment.comment", "Prims.op_Hat", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Combinators.parse_dtuple2_eq'", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "Prims.op_BarBar", "EverParse3d.Kinds.and_then_kind", "Prims.dtuple2", "EverParse3d.Prelude.parse_dep_pair", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.eloc_union", "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.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_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 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; 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
false
Hacl.P256.PrecompTable.fst
Hacl.P256.PrecompTable.proj_point_to_list
val proj_point_to_list: p:S.proj_point -> x:list uint64{FStar.List.Tot.length x = 12 /\ mk_to_p256_comm_monoid.BE.linv (Seq.seq_of_list x)}
val proj_point_to_list: p:S.proj_point -> x:list uint64{FStar.List.Tot.length x = 12 /\ mk_to_p256_comm_monoid.BE.linv (Seq.seq_of_list x)}
let proj_point_to_list p = SPTK.proj_point_to_list_lemma p; SPTK.proj_point_to_list p
{ "file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 29, "start_col": 0, "start_line": 27 }
module Hacl.P256.PrecompTable open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module SPT = Hacl.Spec.PrecompBaseTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module SPTK = Hacl.Spec.P256.PrecompTable module S = Spec.P256 module SL = Spec.P256.Lemmas open Hacl.Impl.P256.Point include Hacl.Impl.P256.Group #set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.PrecompTable.fsti.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Group.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.PrecompTable", "short_module": "SPTK" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
p: Spec.P256.PointOps.proj_point -> x: Prims.list Lib.IntTypes.uint64 { FStar.List.Tot.Base.length x = 12 /\ Mkto_comm_monoid?.linv Hacl.Impl.P256.Group.mk_to_p256_comm_monoid (FStar.Seq.Base.seq_of_list x) }
Prims.Tot
[ "total" ]
[]
[ "Spec.P256.PointOps.proj_point", "Hacl.Spec.P256.PrecompTable.proj_point_to_list", "Prims.unit", "Hacl.Spec.P256.PrecompTable.proj_point_to_list_lemma", "Prims.list", "Lib.IntTypes.uint64", "Prims.l_and", "Prims.b2t", "Prims.op_Equality", "Prims.int", "FStar.List.Tot.Base.length", "Hacl.Impl.Exponentiation.Definitions.__proj__Mkto_comm_monoid__item__linv", "Lib.IntTypes.U64", "FStar.UInt32.uint_to_t", "Hacl.Impl.P256.Group.mk_to_p256_comm_monoid", "FStar.Seq.Base.seq_of_list" ]
[]
false
false
false
false
false
let proj_point_to_list p =
SPTK.proj_point_to_list_lemma p; SPTK.proj_point_to_list p
false
Hacl.P256.PrecompTable.fst
Hacl.P256.PrecompTable.lemma_refl
val lemma_refl: x:S.proj_point -> Lemma (S.mk_p256_concrete_ops.SE.to.SE.refl x == mk_to_p256_comm_monoid.BE.refl (Seq.seq_of_list (proj_point_to_list x)))
val lemma_refl: x:S.proj_point -> Lemma (S.mk_p256_concrete_ops.SE.to.SE.refl x == mk_to_p256_comm_monoid.BE.refl (Seq.seq_of_list (proj_point_to_list x)))
let lemma_refl x = SPTK.proj_point_to_list_lemma x
{ "file_name": "code/ecdsap256/Hacl.P256.PrecompTable.fst", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 32, "start_col": 0, "start_line": 31 }
module Hacl.P256.PrecompTable open FStar.HyperStack open FStar.HyperStack.ST open FStar.Mul open Lib.IntTypes open Lib.Buffer module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module LE = Lib.Exponentiation module SE = Spec.Exponentiation module SPT = Hacl.Spec.PrecompBaseTable module SPT256 = Hacl.Spec.PrecompBaseTable256 module SPTK = Hacl.Spec.P256.PrecompTable module S = Spec.P256 module SL = Spec.P256.Lemmas open Hacl.Impl.P256.Point include Hacl.Impl.P256.Group #set-options "--z3rlimit 50 --fuel 0 --ifuel 0" let proj_point_to_list p = SPTK.proj_point_to_list_lemma p; SPTK.proj_point_to_list p
{ "checked_file": "/", "dependencies": [ "Spec.P256.Lemmas.fsti.checked", "Spec.P256.fst.checked", "Spec.Exponentiation.fsti.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.Exponentiation.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.PrecompBaseTable256.fsti.checked", "Hacl.Spec.PrecompBaseTable.fsti.checked", "Hacl.Spec.P256.PrecompTable.fsti.checked", "Hacl.Impl.P256.Point.fsti.checked", "Hacl.Impl.P256.Group.fst.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.List.Tot.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked" ], "interface_file": true, "source_file": "Hacl.P256.PrecompTable.fst" }
[ { "abbrev": true, "full_module": "Spec.P256.Lemmas", "short_module": "SL" }, { "abbrev": true, "full_module": "Hacl.Spec.P256.PrecompTable", "short_module": "SPTK" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable256", "short_module": "SPT256" }, { "abbrev": true, "full_module": "Lib.Exponentiation", "short_module": "LE" }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Group", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.P256.Point", "short_module": null }, { "abbrev": true, "full_module": "Hacl.Spec.P256.Montgomery", "short_module": "SM" }, { "abbrev": true, "full_module": "Spec.P256", "short_module": "S" }, { "abbrev": true, "full_module": "Hacl.Spec.PrecompBaseTable", "short_module": "SPT" }, { "abbrev": true, "full_module": "Hacl.Impl.Exponentiation.Definitions", "short_module": "BE" }, { "abbrev": true, "full_module": "Spec.Exponentiation", "short_module": "SE" }, { "abbrev": true, "full_module": "Lib.Exponentiation.Definition", "short_module": "LE" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.ST", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "Hacl.P256", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 0, "initial_ifuel": 0, "max_fuel": 0, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
x: Spec.P256.PointOps.proj_point -> FStar.Pervasives.Lemma (ensures Mkto_comm_monoid?.refl (Mkconcrete_ops?.to Spec.P256.mk_p256_concrete_ops) x == Mkto_comm_monoid?.refl Hacl.Impl.P256.Group.mk_to_p256_comm_monoid (FStar.Seq.Base.seq_of_list (Hacl.P256.PrecompTable.proj_point_to_list x)))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "Spec.P256.PointOps.proj_point", "Hacl.Spec.P256.PrecompTable.proj_point_to_list_lemma", "Prims.unit" ]
[]
true
false
true
false
false
let lemma_refl x =
SPTK.proj_point_to_list_lemma x
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_t_exact
val validate_t_exact (n:U32.t) (#nz:bool) (#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) (#ar:_) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv disj l false)
val validate_t_exact (n:U32.t) (#nz:bool) (#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) (#ar:_) (v:validate_with_action_t p inv disj l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv disj l false)
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
{ "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": 9, "end_line": 1414, "start_col": 0, "start_line": 1379 }
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
{ "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", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 128, "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 -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_t_exact n p) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "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", "Prims.op_Negation", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_not_enough_data", "FStar.UInt64.t", "EverParse3d.ErrorCode.is_error", "EverParse3d.ErrorCode.validator_error_unexpected_padding", "Prims.unit", "EverParse3d.InputStream.Base.is_prefix_of_prop", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.InputStream.Base.has", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validate_drop", "LowParse.Spec.Combinators.nondep_then_eq", "EverParse3d.Kinds.kind_all_bytes", "EverParse3d.Prelude.all_bytes", "EverParse3d.Prelude.parse_all_bytes", "EverParse3d.InputStream.Base.get_remaining", "Prims._assert", "FStar.Seq.Base.equal", "FStar.UInt8.t", "FStar.Seq.Base.slice", "FStar.UInt32.v", "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.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind_t_exact", "EverParse3d.Prelude.t_exact", "EverParse3d.Prelude.parse_t_exact" ]
[]
false
false
false
false
false
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 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
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list_up_to
val 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
val 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
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
{ "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": 10, "end_line": 1720, "start_col": 0, "start_line": 1695 }
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
{ "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
v: EverParse3d.Actions.Base.validator p -> r: EverParse3d.Actions.Base.leaf_reader p -> terminator: t -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond (EverParse3d.Prelude.cond_string_up_to terminator) p -> EverParse3d.Actions.Base.validate_with_action_t (LowParse.Spec.ListUpTo.parse_list_up_to (EverParse3d.Prelude.cond_string_up_to terminator) p prf) 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", "LowParse.Spec.ListUpTo.consumes_if_not_cond", "EverParse3d.Prelude.cond_string_up_to", "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", "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_up_to_inv", "EverParse3d.Actions.Base.validate_list_up_to_body", "Prims.bool", "EverParse3d.InputStream.Base.live_not_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "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", "EverParse3d.Actions.Base.validate_with_action_t", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.parse_list_up_to", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.disjointness_trivial", "EverParse3d.Actions.Base.eloc_none" ]
[]
false
false
false
false
false
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
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_t_at_most
val validate_t_at_most (n:U32.t) (#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) (#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)
val validate_t_at_most (n:U32.t) (#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) (#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)
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
{ "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": 9, "end_line": 1371, "start_col": 0, "start_line": 1339 }
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
{ "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", "smt.arith.nl=false" ], "z3refresh": false, "z3rlimit": 64, "z3rlimit_factor": 16, "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 -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_t_at_most n p) inv disj l false
Prims.Tot
[ "total" ]
[]
[ "FStar.UInt32.t", "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", "Prims.op_Negation", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_not_enough_data", "FStar.UInt64.t", "EverParse3d.ErrorCode.is_error", "FStar.UInt64.add", "FStar.Int.Cast.uint32_to_uint64", "Prims.unit", "EverParse3d.InputStream.Base.is_prefix_of_prop", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.InputStream.Base.empty", "EverParse3d.Actions.Base.validate_drop", "LowParse.Spec.Combinators.nondep_then_eq", "EverParse3d.Kinds.kind_all_bytes", "EverParse3d.Prelude.all_bytes", "EverParse3d.Prelude.parse_all_bytes", "EverParse3d.InputStream.Base.get_remaining", "Prims._assert", "FStar.Seq.Base.equal", "FStar.UInt8.t", "FStar.Seq.Base.slice", "FStar.UInt32.v", "EverParse3d.InputStream.Base.__proj__Mkinput_stream_inst__item__tlen", "EverParse3d.InputStream.Base.truncate_len", "EverParse3d.InputStream.Base.truncate", "EverParse3d.InputStream.Base.has", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind_t_at_most", "EverParse3d.Prelude.t_at_most", "EverParse3d.Prelude.parse_t_at_most" ]
[]
false
false
false
false
false
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 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)
false
LowParse.Spec.ListUpTo.fst
LowParse.Spec.ListUpTo.serialize_list_up_to_eq
val serialize_list_up_to_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (xy: parse_list_up_to_t cond) : Lemma (serialize (serialize_list_up_to cond prf s) xy == ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to cond prf s) (y, z) ))
val serialize_list_up_to_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (xy: parse_list_up_to_t cond) : Lemma (serialize (serialize_list_up_to cond prf s) xy == ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to cond prf s) (y, z) ))
let serialize_list_up_to_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (xy: parse_list_up_to_t cond) : Lemma (serialize (serialize_list_up_to cond prf s) xy == ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to cond prf s) (y, z) )) = serialize_list_up_to_fuel_eq cond s (L.length (fst xy) + 1) (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": 78, "end_line": 507, "start_col": 0, "start_line": 492 }
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 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) |) let synth_list_up_to_fuel_inverse (#t: Type) (cond: (t -> Tot bool)) (fuel: nat) : Lemma (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel)) [SMTPat (synth_inverse (synth_list_up_to_fuel cond fuel) (synth_list_up_to_fuel_recip cond fuel))] = () let rec serialize_list_up_to_fuel (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) : Tot (serializer (parse_list_up_to_fuel cond p fuel)) (decreases fuel) = if fuel = 0 then fail_serializer (parse_list_up_to_kind k) (parse_list_up_to_fuel_t cond fuel) (fun _ -> ()) else serialize_synth (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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () let serialize_list_up_to_fuel_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (fuel: nat) (xy: parse_list_up_to_fuel_t cond fuel) : Lemma (serialize (serialize_list_up_to_fuel cond s fuel) xy `Seq.equal` ( let (l, z) = xy in match l with | [] -> serialize s z | x :: y -> serialize s x `Seq.append` serialize (serialize_list_up_to_fuel cond s (fuel - 1)) ((y <: llist (refine_with_cond (negate_cond cond)) (fuel - 1)), z) )) = serialize_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)) (serialize_dtuple2 (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1)))) (synth_list_up_to_fuel_recip cond (fuel - 1)) () xy; serialize_dtuple2_eq' (serialize_weaken (parse_list_up_to_kind k) s) #(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))) (serialize_list_up_to_payload cond (fuel - 1) k (serialize_list_up_to_fuel cond s (fuel - 1))) (synth_list_up_to_fuel_recip cond (fuel - 1) xy) let serialize_list_up_to' (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (bare_serializer (parse_list_up_to_t cond)) = fun xy -> serialize (serialize_list_up_to_fuel cond s (L.length (fst xy) + 1)) (fst xy, snd xy) let serialize_list_up_to_correct (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) (xy: parse_list_up_to_t cond) : Lemma ( let sq = serialize_list_up_to' cond s xy in parse (parse_list_up_to cond p prf) sq == Some (xy, Seq.length sq) ) = let sq = serialize_list_up_to' cond s xy in let fuel' = close_parse_list_up_to sq in let fuel = L.length (fst xy) + 1 in parse_list_up_to'_eq cond p fuel' sq; parse_list_up_to_fuel_length cond p prf fuel sq; parse_list_up_to_fuel_indep cond p fuel sq (fst xy, snd xy) (Seq.length sq) fuel' let serialize_list_up_to (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p { k.parser_kind_subkind == Some ParserStrong }) : Tot (serializer (parse_list_up_to cond p prf)) = Classical.forall_intro (serialize_list_up_to_correct cond prf s); serialize_list_up_to' cond s
{ "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) -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond cond p -> s: LowParse.Spec.Base.serializer p { Mkparser_kind'?.parser_kind_subkind k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } -> xy: LowParse.Spec.ListUpTo.parse_list_up_to_t cond -> FStar.Pervasives.Lemma (ensures LowParse.Spec.Base.serialize (LowParse.Spec.ListUpTo.serialize_list_up_to cond prf s) xy == (let _ = xy in (let FStar.Pervasives.Native.Mktuple2 #_ #_ l z = _ in (match l with | Prims.Nil #_ -> LowParse.Spec.Base.serialize s z | Prims.Cons #_ x y -> FStar.Seq.Base.append (LowParse.Spec.Base.serialize s x) (LowParse.Spec.Base.serialize (LowParse.Spec.ListUpTo.serialize_list_up_to cond prf s) (y, z))) <: FStar.Seq.Base.seq LowParse.Bytes.byte) <: FStar.Seq.Base.seq LowParse.Bytes.byte))
FStar.Pervasives.Lemma
[ "lemma" ]
[]
[ "LowParse.Spec.Base.parser_kind", "Prims.bool", "LowParse.Spec.Base.parser", "LowParse.Spec.ListUpTo.consumes_if_not_cond", "LowParse.Spec.Base.serializer", "Prims.eq2", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "LowParse.Spec.ListUpTo.parse_list_up_to_t", "LowParse.Spec.ListUpTo.serialize_list_up_to_fuel_eq", "Prims.op_Addition", "FStar.List.Tot.Base.length", "LowParse.Spec.ListUpTo.refine_with_cond", "LowParse.Spec.ListUpTo.negate_cond", "FStar.Pervasives.Native.fst", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "LowParse.Spec.ListUpTo.llist", "FStar.Pervasives.Native.snd", "Prims.unit", "Prims.l_True", "Prims.squash", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "LowParse.Spec.Base.serialize", "LowParse.Spec.ListUpTo.parse_list_up_to_kind", "LowParse.Spec.ListUpTo.parse_list_up_to", "LowParse.Spec.ListUpTo.serialize_list_up_to", "FStar.Seq.Base.append", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
true
false
true
false
false
let serialize_list_up_to_eq (#k: parser_kind) (#t: Type) (cond: (t -> Tot bool)) (#p: parser k t) (prf: consumes_if_not_cond cond p) (s: serializer p {k.parser_kind_subkind == Some ParserStrong}) (xy: parse_list_up_to_t cond) : Lemma (serialize (serialize_list_up_to cond prf s) xy == (let l, z = xy in match l with | [] -> serialize s z | x :: y -> (serialize s x) `Seq.append` (serialize (serialize_list_up_to cond prf s) (y, z)))) =
serialize_list_up_to_fuel_eq cond s (L.length (fst xy) + 1) (fst xy, snd xy)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_list_up_to_body
val 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))
val 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 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
{ "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": 1691, "start_col": 0, "start_line": 1656 }
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
{ "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
terminator: t -> prf: LowParse.Spec.ListUpTo.consumes_if_not_cond (EverParse3d.Prelude.cond_string_up_to terminator) p -> v: EverParse3d.Actions.Base.validator p -> r: EverParse3d.Actions.Base.leaf_reader p -> 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 -> h0: FStar.Monotonic.HyperStack.mem -> 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", "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.validator", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "FStar.Monotonic.HyperStack.mem", "LowStar.Buffer.pointer", "FStar.UInt64.t", "EverParse3d.ErrorCode.is_error", "Prims.bool", "Prims.unit", "LowStar.Monotonic.Buffer.upd", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "LowStar.BufferOps.op_Bang_Star", "LowParse.Spec.ListUpTo.parse_list_up_to_eq", "EverParse3d.InputStream.Base.get_remaining", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.validate_list_up_to_inv", "Prims.l_and" ]
[]
false
true
false
false
false
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 true else let value = r sl position in cond_string_up_to terminator value
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.probe_then_validate
val probe_then_validate (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (src:U64.t) (len:U64.t) (dest:CP.copy_buffer_t) (probe:CP.probe_fn) : action (conj_inv inv (copy_buffer_inv dest)) (conj_disjointness disj (disjoint (copy_buffer_loc dest) l)) (eloc_union l (copy_buffer_loc dest)) true bool
val probe_then_validate (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#inv:slice_inv) (#disj:disjointness_pre) (#l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (src:U64.t) (len:U64.t) (dest:CP.copy_buffer_t) (probe:CP.probe_fn) : action (conj_inv inv (copy_buffer_inv dest)) (conj_disjointness disj (disjoint (copy_buffer_loc dest) l)) (eloc_union l (copy_buffer_loc dest)) true bool
let probe_then_validate (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#inv:slice_inv) (#disj:_) (#l:eloc) (#allow_reading:bool) (v:validate_with_action_t p inv disj l allow_reading) (src:U64.t) (len:U64.t) (dest:CP.copy_buffer_t) (probe:CP.probe_fn) = fun ctxt error_handler_fn input input_length pos posf -> CP.properties dest; let h0 = HST.get () in let b = probe src len dest in if b then ( let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; let result = v ctxt error_handler_fn (CP.stream_of dest) (CP.stream_len dest) 0uL in not (LPE.is_error result) ) else false
{ "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": 16, "end_line": 1881, "start_col": 0, "start_line": 1855 }
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 let external_action l = unit -> Stack unit (fun _ -> True) (fun h0 _ h1 -> B.modifies l h0 h1) noextract inline_for_extraction let mk_external_action #_ f = fun _ _ _ _ _ _ -> f () let copy_buffer_inv (x:CP.copy_buffer_t) : slice_inv = CP.properties x; F.on HS.mem #prop (CP.inv x) let copy_buffer_loc (x:CP.copy_buffer_t) : eloc = CP.loc_of x 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": "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
v: EverParse3d.Actions.Base.validate_with_action_t p inv disj l allow_reading -> src: FStar.UInt64.t -> len: FStar.UInt64.t -> dest: EverParse3d.CopyBuffer.copy_buffer_t -> probe: EverParse3d.CopyBuffer.probe_fn -> EverParse3d.Actions.Base.action (EverParse3d.Actions.Base.conj_inv inv (EverParse3d.Actions.Base.copy_buffer_inv dest)) (EverParse3d.Actions.Base.conj_disjointness disj (EverParse3d.Actions.Base.disjoint (EverParse3d.Actions.Base.copy_buffer_loc dest) l)) (EverParse3d.Actions.Base.eloc_union l (EverParse3d.Actions.Base.copy_buffer_loc dest)) true Prims.bool
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", "FStar.UInt64.t", "EverParse3d.CopyBuffer.copy_buffer_t", "EverParse3d.CopyBuffer.probe_fn", "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.is_error", "EverParse3d.CopyBuffer.stream_of", "EverParse3d.CopyBuffer.stream_len", "FStar.UInt64.__uint_to_t", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.CopyBuffer.properties" ]
[]
false
false
false
false
false
let probe_then_validate (#nz: bool) (#wk: _) (#k: parser_kind nz wk) (#t: Type) (#p: parser k t) (#inv: slice_inv) (#disj: _) (#l: eloc) (#allow_reading: bool) (v: validate_with_action_t p inv disj l allow_reading) (src len: U64.t) (dest: CP.copy_buffer_t) (probe: CP.probe_fn) =
fun ctxt error_handler_fn input input_length pos posf -> CP.properties dest; let h0 = HST.get () in let b = probe src len dest in if b then (let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; let result = v ctxt error_handler_fn (CP.stream_of dest) (CP.stream_len dest) 0uL in not (LPE.is_error result)) else false
false
GenMakefile.fst
GenMakefile.input_dir
val input_dir : Prims.string
let input_dir = "$(EVERPARSE_INPUT_DIR)"
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 40, "end_line": 16, "start_col": 0, "start_line": 16 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.string
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let input_dir =
"$(EVERPARSE_INPUT_DIR)"
false
GenMakefile.fst
GenMakefile.output_dir
val output_dir : Prims.string
let output_dir = "$(EVERPARSE_OUTPUT_DIR)"
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 42, "end_line": 17, "start_col": 0, "start_line": 17 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.string
Prims.Tot
[ "total" ]
[]
[]
[]
false
false
false
true
false
let output_dir =
"$(EVERPARSE_OUTPUT_DIR)"
false
Steel.Channel.Simplex.fst
Steel.Channel.Simplex.intro_trace_until
val 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)
val 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)
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))); ()
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 6, "end_line": 181, "start_col": 0, "start_line": 171 }
(* 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}
{ "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 -> v: Steel.Channel.Simplex.chan_val -> Steel.Effect.Steel Prims.unit
Steel.Effect.Steel
[]
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.trace_ref", "Steel.Channel.Protocol.partial_trace_of", "Steel.Channel.Simplex.chan_val", "Prims.unit", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.MonotonicHigherReference.pts_to", "Steel.Channel.Protocol.extended_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.pure", "Prims.eq2", "Steel.Channel.Protocol.protocol", "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", "Steel.Effect.Common.vprop", "Steel.Effect.Atomic.intro_pure", "Steel.Channel.Simplex.trace_until", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
false
true
false
false
false
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)))); ()
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_dep_pair_with_refinement_and_action_total_zero_parser'
val 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))
val 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))
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
{ "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": 11, "end_line": 582, "start_col": 0, "start_line": 535 }
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
{ "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
name1: Prims.string -> r1: EverParse3d.Actions.Base.leaf_reader p1 -> inv1: EverParse3d.Actions.Base.slice_inv -> disj1: EverParse3d.Actions.Base.disjointness_pre -> l1: EverParse3d.Actions.Base.eloc -> 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 ar2) -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (LowParse.Spec.Combinators.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.Pure
[]
[]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.disjointness_pre", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.action", "EverParse3d.Kinds.weak_kind", "EverParse3d.Prelude.refine", "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_error", "FStar.UInt64.t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_action_failed", "EverParse3d.Actions.Base.validate_drop", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.op_Negation", "EverParse3d.ErrorCode.check_constraint_ok", "LowStar.Comment.comment", "Prims.op_Hat", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Combinators.parse_dtuple2_eq'", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "Prims.op_BarBar", "EverParse3d.Kinds.and_then_kind", "Prims.dtuple2", "EverParse3d.Prelude.parse_dep_pair", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.conj_disjointness", "EverParse3d.Actions.Base.eloc_union", "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.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_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 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 else 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
false
GenMakefile.fst
GenMakefile.mk_input_filename
val mk_input_filename (file: string) : Tot string
val mk_input_filename (file: string) : Tot string
let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 40, "end_line": 62, "start_col": 0, "start_line": 59 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
file: Prims.string -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "OS.concat", "GenMakefile.input_dir", "OS.basename" ]
[]
false
false
false
true
false
let mk_input_filename (file: string) : Tot string =
input_dir `OS.concat` (OS.basename file)
false
GenMakefile.fst
GenMakefile.mk_filename
val mk_filename (modul ext: string) : Tot string
val mk_filename (modul ext: string) : Tot string
let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext)
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 59, "end_line": 68, "start_col": 0, "start_line": 64 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
modul: Prims.string -> ext: Prims.string -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.string", "OS.concat", "GenMakefile.output_dir", "FStar.Printf.sprintf" ]
[]
false
false
false
true
false
let mk_filename (modul ext: string) : Tot string =
output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext)
false
GenMakefile.fst
GenMakefile.has_external_types_fsti
val has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool
val has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool
let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul)
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 34, "end_line": 110, "start_col": 0, "start_line": 104 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "Prims.op_BarBar", "Deps.has_output_types", "Deps.has_extern_types", "Prims.bool" ]
[]
false
false
false
true
false
let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool =
(Deps.has_output_types g modul || Deps.has_extern_types g modul)
false
GenMakefile.fst
GenMakefile.maybe_external_types_fsti_checked
val maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string)
val maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string)
let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 118, "start_col": 0, "start_line": 112 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.has_external_types_fsti", "Prims.Cons", "GenMakefile.mk_filename", "Prims.Nil", "Prims.bool", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) =
if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else []
false
GenMakefile.fst
GenMakefile.produce_config_fst_file_rule
val produce_config_fst_file_rule: Prims.unit -> FStar.All.ML (list rule_t)
val produce_config_fst_file_rule: Prims.unit -> FStar.All.ML (list rule_t)
let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 11, "end_line": 102, "start_col": 0, "start_line": 76 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.All.ML (Prims.list GenMakefile.rule_t)
FStar.All.ML
[ "ml" ]
[]
[ "Prims.unit", "Prims.string", "Prims.Cons", "GenMakefile.rule_t", "Prims.Nil", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.Printf.sprintf", "GenMakefile.mk_filename", "FStar.Pervasives.Native.tuple2", "FStar.Pervasives.Native.option", "Prims.list", "FStar.Pervasives.Native.Mktuple2", "Options.get_config_file", "Options.config_module_name" ]
[]
false
true
false
false
false
let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) =
match Options.config_module_name (), Options.get_config_file () with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name } in [fst_rule; fst_checked_rule; krml_rule] | _ -> []
false
GenMakefile.fst
GenMakefile.oext
val oext : _: HashingOptions.makefile_type -> Prims.string
let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj"
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 39, "end_line": 21, "start_col": 0, "start_line": 19 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)"
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
_: HashingOptions.makefile_type -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "HashingOptions.makefile_type", "Prims.string" ]
[]
false
false
false
true
false
let oext =
function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj"
false
GenMakefile.fst
GenMakefile.has_external_api_fsti
val has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool
val has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool
let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 35, "end_line": 128, "start_col": 0, "start_line": 120 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.bool
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "Prims.op_BarBar", "Deps.has_extern_probe", "Deps.has_out_exprs", "Deps.has_extern_types", "Deps.has_extern_functions", "Prims.bool" ]
[]
false
false
false
true
false
let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool =
Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul
false
GenMakefile.fst
GenMakefile.produce_external_api_fsti_checked_rule
val produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t
val produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t
let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }]
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 142, "start_col": 0, "start_line": 130 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "Prims.op_Negation", "GenMakefile.has_external_api_fsti", "Prims.Nil", "GenMakefile.rule_t", "Prims.bool", "Prims.Cons", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.List.Tot.Base.append", "GenMakefile.maybe_external_types_fsti_checked", "FStar.List.Tot.Base.map", "GenMakefile.mk_filename", "Deps.dependencies", "FStar.Printf.sprintf", "Prims.list" ]
[]
false
false
false
true
false
let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t =
if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [ { ty = EverParse; from = external_api_fsti :: ((maybe_external_types_fsti_checked g modul) `List.Tot.append` (List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul))); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti } ]
false
GenMakefile.fst
GenMakefile.produce_external_types_fsti_checked_rule
val produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t
val produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t
let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }]
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 156, "start_col": 0, "start_line": 144 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "Prims.op_Negation", "GenMakefile.has_external_types_fsti", "Prims.Nil", "GenMakefile.rule_t", "Prims.bool", "Prims.Cons", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.List.Tot.Base.map", "GenMakefile.mk_filename", "Deps.dependencies", "FStar.Printf.sprintf", "Prims.list" ]
[]
false
false
false
true
false
let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t =
if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [ { ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti } ]
false
GenMakefile.fst
GenMakefile.maybe_external_api_fsti_checked
val maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string)
val maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string)
let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 164, "start_col": 0, "start_line": 158 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.has_external_api_fsti", "Prims.Cons", "GenMakefile.mk_filename", "Prims.Nil", "Prims.bool", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) =
if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else []
false
GenMakefile.fst
GenMakefile.external_deps
val external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string)
val external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string)
let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 41, "end_line": 171, "start_col": 0, "start_line": 166 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "FStar.List.Tot.Base.append", "GenMakefile.maybe_external_types_fsti_checked", "GenMakefile.maybe_external_api_fsti_checked", "Prims.list" ]
[]
false
false
false
true
false
let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) =
(maybe_external_types_fsti_checked g modul) `List.Tot.append` (maybe_external_api_fsti_checked g modul)
false
GenMakefile.fst
GenMakefile.produce_fsti_checked_rule
val produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t
val produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t
let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; }
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 183, "start_col": 0, "start_line": 173 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "Prims.Cons", "FStar.List.Tot.Base.append", "GenMakefile.external_deps", "FStar.List.Tot.Base.map", "GenMakefile.mk_filename", "Deps.dependencies", "FStar.Printf.sprintf", "GenMakefile.rule_t" ]
[]
false
false
false
true
false
let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t =
let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: ((external_deps g modul) `List.Tot.append` (List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul))); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti }
false
GenMakefile.fst
GenMakefile.produce_fst_checked_rule
val produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t
val produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t
let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; }
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 195, "start_col": 0, "start_line": 185 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> FStar.All.ML GenMakefile.rule_t
FStar.All.ML
[ "ml" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "GenMakefile.rule_t", "Prims.list", "GenMakefile.add_cfg_file_dep", "Prims.Cons", "FStar.List.Tot.Base.map", "Deps.dependencies" ]
[]
false
true
false
false
false
let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t =
let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst }
false
GenMakefile.fst
GenMakefile.produce_external_types_krml_rule
val produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t
val produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t
let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }]
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 209, "start_col": 0, "start_line": 197 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "Prims.op_Negation", "GenMakefile.has_external_types_fsti", "Prims.Nil", "GenMakefile.rule_t", "Prims.bool", "Prims.Cons", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.List.Tot.Base.map", "GenMakefile.mk_filename", "Deps.dependencies", "FStar.Printf.sprintf", "Prims.list" ]
[]
false
false
false
true
false
let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t =
if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [ { ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti") } ]
false
Steel.SpinLock.fst
Steel.SpinLock.release_core
val release_core (#p:vprop) (#u:inames) (r:ref bool) (i:inv (lockinv p r)) : SteelAtomicT bool u (lockinv p r `star` p) (fun b -> lockinv p r `star` (if b then emp else p))
val release_core (#p:vprop) (#u:inames) (r:ref bool) (i:inv (lockinv p r)) : SteelAtomicT bool u (lockinv p r `star` p) (fun b -> lockinv p r `star` (if b then emp else p))
let release_core #p #u r i = let v = witness_exists () in let res = cas_pt_bool r v locked available in (* Not sure we can avoid calling an SMT here. Better force the manual call? *) rewrite_slprop (if (Ghost.reveal v) then emp else p) (if res then emp else p) (fun _ -> ()); rewrite_slprop (if res then pts_to r full_perm (Ghost.hide available) else pts_to r full_perm v) (pts_to r full_perm available) (fun _ -> ()); intro_lockinv_available p r; return res
{ "file_name": "lib/steel/Steel.SpinLock.fst", "git_rev": "f984200f79bdc452374ae994a5ca837496476c41", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
{ "end_col": 12, "end_line": 107, "start_col": 0, "start_line": 96 }
(* 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 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 ) val release_core (#p:vprop) (#u:inames) (r:ref bool) (i:inv (lockinv p r)) : SteelAtomicT bool u (lockinv p r `star` p) (fun b -> lockinv p r `star` (if b then emp else p))
{ "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", "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
r: Steel.Reference.ref Prims.bool -> i: Steel.Effect.Common.inv (Steel.SpinLock.lockinv p r) -> Steel.Effect.Atomic.SteelAtomicT Prims.bool
Steel.Effect.Atomic.SteelAtomicT
[]
[]
[ "Steel.Effect.Common.vprop", "Steel.Memory.inames", "Steel.Reference.ref", "Prims.bool", "Steel.Effect.Common.inv", "Steel.SpinLock.lockinv", "Steel.Effect.Atomic.return", "Steel.Effect.Common.VStar", "Steel.Effect.Common.emp", "Prims.unit", "Steel.SpinLock.intro_lockinv_available", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Reference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.SpinLock.available", "FStar.Ghost.reveal", "Steel.Memory.mem", "Prims.l_iff", "Prims.b2t", "Prims.eq2", "Steel.SpinLock.locked", "Steel.Reference.cas_pt_bool", "FStar.Ghost.erased", "Steel.Effect.Atomic.witness_exists", "Steel.Effect.Common.star" ]
[]
false
true
false
false
false
let release_core #p #u r i =
let v = witness_exists () in let res = cas_pt_bool r v locked available in rewrite_slprop (if (Ghost.reveal v) then emp else p) (if res then emp else p) (fun _ -> ()); rewrite_slprop (if res then pts_to r full_perm (Ghost.hide available) else pts_to r full_perm v) (pts_to r full_perm available) (fun _ -> ()); intro_lockinv_available p r; return res
false
GenMakefile.fst
GenMakefile.produce_krml_rule
val produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t
val produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t
let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); }
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 237, "start_col": 0, "start_line": 225 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> FStar.All.ML GenMakefile.rule_t
FStar.All.ML
[ "ml" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "GenMakefile.rule_t", "Prims.list", "GenMakefile.add_cfg_file_dep", "Prims.Cons", "FStar.List.Tot.Base.map", "Deps.dependencies" ]
[]
false
true
false
false
false
let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t =
{ ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst") }
false
GenMakefile.fst
GenMakefile.produce_external_api_krml_rule
val produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t
val produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t
let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }]
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 7, "end_line": 223, "start_col": 0, "start_line": 211 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> modul: Prims.string -> Prims.list GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "Prims.op_Negation", "GenMakefile.has_external_api_fsti", "Prims.Nil", "GenMakefile.rule_t", "Prims.bool", "Prims.Cons", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.List.Tot.Base.map", "GenMakefile.mk_filename", "Deps.dependencies", "FStar.Printf.sprintf", "Prims.list" ]
[]
false
false
false
true
false
let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t =
if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [ { ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti") } ]
false
GenMakefile.fst
GenMakefile.maybe_external_typedefs_h
val maybe_external_typedefs_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (modul: string) : Tot (list string)
val maybe_external_typedefs_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (modul: string) : Tot (list string)
let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 258, "start_col": 0, "start_line": 251 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
emit_output_types_defs: Prims.bool -> g: Deps.dep_graph -> modul: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Deps.dep_graph", "Prims.string", "Prims.op_AmpAmp", "Deps.has_output_types", "Prims.op_Negation", "Deps.has_extern_types", "Prims.Cons", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "Prims.Nil", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_typedefs_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (modul: string) : Tot (list string) =
if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else []
false
GenMakefile.fst
GenMakefile.produce_nop_rule
val produce_nop_rule (from: list string) (to: string) : Tot rule_t
val produce_nop_rule (from: list string) (to: string) : Tot rule_t
let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; }
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 3, "end_line": 249, "start_col": 0, "start_line": 239 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
from: Prims.list Prims.string -> to: Prims.string -> GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "Prims.string", "GenMakefile.Mkrule_t", "GenMakefile.Nop", "GenMakefile.rule_t" ]
[]
false
false
false
true
false
let produce_nop_rule (from: list string) (to: string) : Tot rule_t =
{ ty = Nop; from = from; to = to; args = "" }
false
GenMakefile.fst
GenMakefile.maybe_external_api_krml
val maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string)
val maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string)
let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 340, "start_col": 0, "start_line": 334 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> m: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.has_external_api_fsti", "Prims.Cons", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "Prims.Nil", "Prims.bool", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) =
if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else []
false
GenMakefile.fst
GenMakefile.maybe_external_types_krml
val maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string)
val maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string)
let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 348, "start_col": 0, "start_line": 342 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> m: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.has_external_types_fsti", "Prims.Cons", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "Prims.Nil", "Prims.bool", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) =
if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else []
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_dep_pair_with_action
val validate_dep_pair_with_action (#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) (#[@@@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:t1 -> Type) (#[@@@erasable] p2:(x:t1 -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:_) (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t (p1 `(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
val validate_dep_pair_with_action (#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) (#[@@@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:t1 -> Type) (#[@@@erasable] p2:(x:t1 -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] disj2:disjointness_pre) (#[@@@erasable] l2:eloc) (#allow_reading2:_) (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 disj2 l2 allow_reading2)) : validate_with_action_t (p1 `(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
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
{ "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": 9, "end_line": 633, "start_col": 0, "start_line": 606 }
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
{ "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
v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 disj1 l1 true -> r1: EverParse3d.Actions.Base.leaf_reader p1 -> a: (_: t1 -> EverParse3d.Actions.Base.action inv1' disj1' l1' b Prims.bool) -> v2: (x: t1 -> 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 p1 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", "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.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", "Prims.op_Negation", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_action_failed", "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.parse_dtuple2_eq'", "EverParse3d.InputStream.Base.get_remaining" ]
[]
false
false
false
false
false
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 res else 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 else validate_drop (v2 field_value) ctxt error_handler_fn input input_length res
false
GenMakefile.fst
GenMakefile.maybe_external_types_h
val maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string)
val maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string)
let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 356, "start_col": 0, "start_line": 350 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> m: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.has_external_types_fsti", "Prims.Cons", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "Prims.Nil", "Prims.bool", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) =
if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else []
false
GenMakefile.fst
GenMakefile.maybe_external_api_h
val maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string)
val maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string)
let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 9, "end_line": 364, "start_col": 0, "start_line": 358 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> m: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "GenMakefile.has_external_api_fsti", "Prims.Cons", "GenMakefile.mk_filename", "FStar.Printf.sprintf", "Prims.Nil", "Prims.bool", "Prims.list" ]
[]
false
false
false
true
false
let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) =
if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else []
false
GenMakefile.fst
GenMakefile.maybe_krml_generated_h
val maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string)
val maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string)
let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 26, "end_line": 371, "start_col": 0, "start_line": 366 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> m: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Deps.dep_graph", "Prims.string", "FStar.List.Tot.Base.append", "GenMakefile.maybe_external_types_h", "GenMakefile.maybe_external_api_h", "Prims.list" ]
[]
false
false
false
true
false
let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) =
(maybe_external_types_h g m) `List.Tot.append` (maybe_external_api_h g m)
false
GenMakefile.fst
GenMakefile.maybe_h
val maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string)
val maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string)
let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_krml_generated_h g m `List.Tot.append` maybe_external_typedefs_h emit_output_types_defs g m
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 54, "end_line": 379, "start_col": 0, "start_line": 373 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else [] let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
emit_output_types_defs: Prims.bool -> g: Deps.dep_graph -> m: Prims.string -> Prims.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Deps.dep_graph", "Prims.string", "FStar.List.Tot.Base.append", "GenMakefile.maybe_krml_generated_h", "GenMakefile.maybe_external_typedefs_h", "Prims.list" ]
[]
false
false
false
true
false
let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) =
(maybe_krml_generated_h g m) `List.Tot.append` (maybe_external_typedefs_h emit_output_types_defs g m)
false
GenMakefile.fst
GenMakefile.produce_h_rules
val produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t)
val produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t)
let produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let all_files = Deps.collect_and_sort_dependencies_from_graph g [file] in let to = mk_filename (Options.get_module_name file) "c" in let copyright = mk_input_filename (Printf.sprintf "%s.3d.copyright.txt" (Options.get_module_name file)) in { ty = EverParse; from = add_cfg_file_dep "krml" ( (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [copyright] else []) `List.Tot.append` List.map (fun f -> mk_filename (Options.get_module_name f) "krml") all_files `List.Tot.append` List.concatMap (fun f -> let m = Options.get_module_name f in maybe_external_api_krml g m `List.Tot.append` maybe_external_types_krml g m ) all_files ) ; to = to; (* IMPORTANT: relies on the fact that KaRaMeL generates .c files BEFORE .h files *) args = Printf.sprintf "--__produce_c_from_existing_krml %s" (mk_input_filename file); } :: produce_nop_rule [to] (mk_filename (Options.get_module_name file) "h") :: List.concatMap (fun f -> let m = Options.get_module_name f in List.Tot.map (produce_nop_rule [to]) (maybe_krml_generated_h g m) ) all_files
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 13, "end_line": 411, "start_col": 0, "start_line": 381 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else [] let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_krml_generated_h g m `List.Tot.append` maybe_external_typedefs_h emit_output_types_defs g m
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
g: Deps.dep_graph -> clang_format: Prims.bool -> file: Prims.string -> FStar.All.ML (Prims.list GenMakefile.rule_t)
FStar.All.ML
[ "ml" ]
[]
[ "Deps.dep_graph", "Prims.bool", "Prims.string", "Prims.Cons", "GenMakefile.rule_t", "Prims.list", "FStar.List.concatMap", "FStar.List.Tot.Base.map", "GenMakefile.produce_nop_rule", "Prims.Nil", "GenMakefile.maybe_krml_generated_h", "Options.get_module_name", "GenMakefile.mk_filename", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.Printf.sprintf", "GenMakefile.mk_input_filename", "GenMakefile.add_cfg_file_dep", "FStar.List.Tot.Base.append", "GenMakefile.maybe_external_api_krml", "GenMakefile.maybe_external_types_krml", "FStar.List.map", "OS.file_exists", "Deps.collect_and_sort_dependencies_from_graph" ]
[]
false
true
false
false
false
let produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) =
let all_files = Deps.collect_and_sort_dependencies_from_graph g [file] in let to = mk_filename (Options.get_module_name file) "c" in let copyright = mk_input_filename (Printf.sprintf "%s.3d.copyright.txt" (Options.get_module_name file)) in { ty = EverParse; from = add_cfg_file_dep "krml" ((((if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [copyright] else [])) `List.Tot.append` (List.map (fun f -> mk_filename (Options.get_module_name f) "krml") all_files)) `List.Tot.append` (List.concatMap (fun f -> let m = Options.get_module_name f in (maybe_external_api_krml g m) `List.Tot.append` (maybe_external_types_krml g m)) all_files)); to = to; args = Printf.sprintf "--__produce_c_from_existing_krml %s" (mk_input_filename file) } :: produce_nop_rule [to] (mk_filename (Options.get_module_name file) "h") :: List.concatMap (fun f -> let m = Options.get_module_name f in List.Tot.map (produce_nop_rule [to]) (maybe_krml_generated_h g m)) all_files
false
GenMakefile.fst
GenMakefile.produce_clang_format_rule
val produce_clang_format_rule (clang_format: bool) : Tot (list rule_t)
val produce_clang_format_rule (clang_format: bool) : Tot (list rule_t)
let produce_clang_format_rule (clang_format: bool) : Tot (list rule_t) = if clang_format then [{ ty = EverParse; from = []; to = mk_filename "" "clang-format"; args = "--__micro_step copy_clang_format"; }] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 12, "end_line": 504, "start_col": 0, "start_line": 494 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else [] let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_krml_generated_h g m `List.Tot.append` maybe_external_typedefs_h emit_output_types_defs g m let produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let all_files = Deps.collect_and_sort_dependencies_from_graph g [file] in let to = mk_filename (Options.get_module_name file) "c" in let copyright = mk_input_filename (Printf.sprintf "%s.3d.copyright.txt" (Options.get_module_name file)) in { ty = EverParse; from = add_cfg_file_dep "krml" ( (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [copyright] else []) `List.Tot.append` List.map (fun f -> mk_filename (Options.get_module_name f) "krml") all_files `List.Tot.append` List.concatMap (fun f -> let m = Options.get_module_name f in maybe_external_api_krml g m `List.Tot.append` maybe_external_types_krml g m ) all_files ) ; to = to; (* IMPORTANT: relies on the fact that KaRaMeL generates .c files BEFORE .h files *) args = Printf.sprintf "--__produce_c_from_existing_krml %s" (mk_input_filename file); } :: produce_nop_rule [to] (mk_filename (Options.get_module_name file) "h") :: List.concatMap (fun f -> let m = Options.get_module_name f in List.Tot.map (produce_nop_rule [to]) (maybe_krml_generated_h g m) ) all_files let c_to_o mtype o c = let oflag = match mtype with | HashingOptions.MakefileGMake -> "-o" | HashingOptions.MakefileNMake -> "/Fo:" in Printf.sprintf "%s %s %s" oflag o c let produce_output_types_o_rule mtype (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul:string) : FStar.All.ML (list rule_t) = if Deps.has_out_exprs g modul then let c = mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c" in let o = mk_filename (Printf.sprintf "%s_OutputTypes" modul) (oext mtype) in [{ ty = CC; from = c :: maybe_external_typedefs_h emit_output_types_defs g modul; to = o; args = c_to_o mtype o c; }] else let _ = FStar.IO.print_string (Printf.sprintf "%s has no output types\n" modul) in [] let produce_o_rule mtype (everparse_h: bool) (modul: string) : Tot rule_t = let c = mk_filename modul "c" in let o = mk_filename modul (oext mtype) in { ty = CC; from = ((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [c; mk_filename modul "h"]); to = o; args = c_to_o mtype o c; } let produce_wrapper_o_rule mtype (everparse_h: bool) (g: Deps.dep_graph) (modul: string) : Tot (list rule_t) = let wc = mk_filename (Printf.sprintf "%sWrapper" modul) "c" in let wh = mk_filename (Printf.sprintf "%sWrapper" modul) "h" in let wo = mk_filename (Printf.sprintf "%sWrapper" modul) (oext mtype) in let h = mk_filename modul "h" in if Deps.has_entrypoint g modul then [{ ty = CC; from =((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [wc; wh; h]); to = wo; args = c_to_o mtype wo wc; }] else [] let produce_static_assertions_o_rule mtype (everparse_h: bool) (g: Deps.dep_graph) (modul: string) : Tot (list rule_t) = let wc = mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c" in let wo = mk_filename (Printf.sprintf "%sStaticAssertions" modul) (oext mtype) in let h = mk_filename modul "h" in if Deps.has_static_assertions g modul then [{ ty = CC; from = ((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [wc; h]); to = wo; args = c_to_o mtype wo wc; }] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
clang_format: Prims.bool -> Prims.list GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.Cons", "GenMakefile.rule_t", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "Prims.Nil", "Prims.string", "GenMakefile.mk_filename", "Prims.list" ]
[]
false
false
false
true
false
let produce_clang_format_rule (clang_format: bool) : Tot (list rule_t) =
if clang_format then [ { ty = EverParse; from = []; to = mk_filename "" "clang-format"; args = "--__micro_step copy_clang_format" } ] else []
false
GenMakefile.fst
GenMakefile.produce_everparse_h_rule
val produce_everparse_h_rule (everparse_h: bool) : Tot (list rule_t)
val produce_everparse_h_rule (everparse_h: bool) : Tot (list rule_t)
let produce_everparse_h_rule (everparse_h: bool) : Tot (list rule_t) = if everparse_h then [ { ty = EverParse; from = []; to = mk_filename "EverParseEndianness" "h"; args = "--__micro_step copy_everparse_h"; }; { ty = Nop; from = [mk_filename "EverParseEndianness" "h"]; to = mk_filename "EverParse" "h"; args = ""; } ] else []
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 11, "end_line": 524, "start_col": 0, "start_line": 506 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else [] let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_krml_generated_h g m `List.Tot.append` maybe_external_typedefs_h emit_output_types_defs g m let produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let all_files = Deps.collect_and_sort_dependencies_from_graph g [file] in let to = mk_filename (Options.get_module_name file) "c" in let copyright = mk_input_filename (Printf.sprintf "%s.3d.copyright.txt" (Options.get_module_name file)) in { ty = EverParse; from = add_cfg_file_dep "krml" ( (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [copyright] else []) `List.Tot.append` List.map (fun f -> mk_filename (Options.get_module_name f) "krml") all_files `List.Tot.append` List.concatMap (fun f -> let m = Options.get_module_name f in maybe_external_api_krml g m `List.Tot.append` maybe_external_types_krml g m ) all_files ) ; to = to; (* IMPORTANT: relies on the fact that KaRaMeL generates .c files BEFORE .h files *) args = Printf.sprintf "--__produce_c_from_existing_krml %s" (mk_input_filename file); } :: produce_nop_rule [to] (mk_filename (Options.get_module_name file) "h") :: List.concatMap (fun f -> let m = Options.get_module_name f in List.Tot.map (produce_nop_rule [to]) (maybe_krml_generated_h g m) ) all_files let c_to_o mtype o c = let oflag = match mtype with | HashingOptions.MakefileGMake -> "-o" | HashingOptions.MakefileNMake -> "/Fo:" in Printf.sprintf "%s %s %s" oflag o c let produce_output_types_o_rule mtype (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul:string) : FStar.All.ML (list rule_t) = if Deps.has_out_exprs g modul then let c = mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c" in let o = mk_filename (Printf.sprintf "%s_OutputTypes" modul) (oext mtype) in [{ ty = CC; from = c :: maybe_external_typedefs_h emit_output_types_defs g modul; to = o; args = c_to_o mtype o c; }] else let _ = FStar.IO.print_string (Printf.sprintf "%s has no output types\n" modul) in [] let produce_o_rule mtype (everparse_h: bool) (modul: string) : Tot rule_t = let c = mk_filename modul "c" in let o = mk_filename modul (oext mtype) in { ty = CC; from = ((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [c; mk_filename modul "h"]); to = o; args = c_to_o mtype o c; } let produce_wrapper_o_rule mtype (everparse_h: bool) (g: Deps.dep_graph) (modul: string) : Tot (list rule_t) = let wc = mk_filename (Printf.sprintf "%sWrapper" modul) "c" in let wh = mk_filename (Printf.sprintf "%sWrapper" modul) "h" in let wo = mk_filename (Printf.sprintf "%sWrapper" modul) (oext mtype) in let h = mk_filename modul "h" in if Deps.has_entrypoint g modul then [{ ty = CC; from =((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [wc; wh; h]); to = wo; args = c_to_o mtype wo wc; }] else [] let produce_static_assertions_o_rule mtype (everparse_h: bool) (g: Deps.dep_graph) (modul: string) : Tot (list rule_t) = let wc = mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c" in let wo = mk_filename (Printf.sprintf "%sStaticAssertions" modul) (oext mtype) in let h = mk_filename modul "h" in if Deps.has_static_assertions g modul then [{ ty = CC; from = ((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [wc; h]); to = wo; args = c_to_o mtype wo wc; }] else [] let produce_clang_format_rule (clang_format: bool) : Tot (list rule_t) = if clang_format then [{ ty = EverParse; from = []; to = mk_filename "" "clang-format"; args = "--__micro_step copy_clang_format"; }] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
everparse_h: Prims.bool -> Prims.list GenMakefile.rule_t
Prims.Tot
[ "total" ]
[]
[ "Prims.bool", "Prims.Cons", "GenMakefile.rule_t", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "Prims.Nil", "Prims.string", "GenMakefile.mk_filename", "GenMakefile.Nop", "Prims.list" ]
[]
false
false
false
true
false
let produce_everparse_h_rule (everparse_h: bool) : Tot (list rule_t) =
if everparse_h then [ { ty = EverParse; from = []; to = mk_filename "EverParseEndianness" "h"; args = "--__micro_step copy_everparse_h" }; { ty = Nop; from = [mk_filename "EverParseEndianness" "h"]; to = mk_filename "EverParse" "h"; args = "" } ] else []
false
GenMakefile.fst
GenMakefile.write_makefile
val write_makefile (mtype: HashingOptions.makefile_type) (_: HashingOptions.input_stream_binding_t) (everparse_h: bool) (emit_output_types_defs: bool) (skip_o_rules: bool) (clang_format: bool) (files: list string) : FStar.All.ML unit
val write_makefile (mtype: HashingOptions.makefile_type) (_: HashingOptions.input_stream_binding_t) (everparse_h: bool) (emit_output_types_defs: bool) (skip_o_rules: bool) (clang_format: bool) (files: list string) : FStar.All.ML unit
let write_makefile mtype input_stream_binding (everparse_h: bool) (emit_output_types_defs: bool) (skip_o_rules: bool) (clang_format: bool) (files: list string) : FStar.All.ML unit = let makefile = Options.get_makefile_name () in let file = FStar.IO.open_write_file makefile in let {graph = g; rules; all_files} = produce_makefile mtype everparse_h emit_output_types_defs skip_o_rules clang_format files in FStar.IO.write_string file (String.concat "" (List.Tot.map (print_make_rule mtype everparse_h input_stream_binding) rules)); let write_all_ext_files (ext_cap: string) (ext: string) : FStar.All.ML unit = let ln = begin if ext = "h" && everparse_h then [mk_filename "EverParse" "h"; mk_filename "EverParseEndianness" "h"] else [] end `List.Tot.append` begin if ext <> "h" then List.concatMap (fun f -> let m = Options.get_module_name f in if Deps.has_static_assertions g m then [mk_filename (Printf.sprintf "%sStaticAssertions" m) ext] else []) all_files else [] end `List.Tot.append` List.concatMap (fun f -> let m = Options.get_module_name f in if Deps.has_entrypoint g m then [mk_filename (Printf.sprintf "%sWrapper" m) ext] else []) all_files `List.Tot.append` begin if ext <> "h" then List.concatMap (fun f -> let m = Options.get_module_name f in if Deps.has_out_exprs g m then [mk_filename (Printf.sprintf "%s_OutputTypes" m) ext] else []) all_files else [] end `List.Tot.append` begin if ext = "h" then List.concatMap (fun f -> let m = Options.get_module_name f in maybe_h emit_output_types_defs g m) all_files else [] end `List.Tot.append` List.map (fun f -> mk_filename (Options.get_module_name f) ext) all_files in FStar.IO.write_string file (Printf.sprintf "EVERPARSE_ALL_%s_FILES=%s\n" ext_cap (String.concat " " ln)) in write_all_ext_files "H" "h"; write_all_ext_files "C" "c"; write_all_ext_files "O" (oext mtype); FStar.IO.close_write_file file
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 32, "end_line": 616, "start_col": 0, "start_line": 570 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else [] let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_krml_generated_h g m `List.Tot.append` maybe_external_typedefs_h emit_output_types_defs g m let produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let all_files = Deps.collect_and_sort_dependencies_from_graph g [file] in let to = mk_filename (Options.get_module_name file) "c" in let copyright = mk_input_filename (Printf.sprintf "%s.3d.copyright.txt" (Options.get_module_name file)) in { ty = EverParse; from = add_cfg_file_dep "krml" ( (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [copyright] else []) `List.Tot.append` List.map (fun f -> mk_filename (Options.get_module_name f) "krml") all_files `List.Tot.append` List.concatMap (fun f -> let m = Options.get_module_name f in maybe_external_api_krml g m `List.Tot.append` maybe_external_types_krml g m ) all_files ) ; to = to; (* IMPORTANT: relies on the fact that KaRaMeL generates .c files BEFORE .h files *) args = Printf.sprintf "--__produce_c_from_existing_krml %s" (mk_input_filename file); } :: produce_nop_rule [to] (mk_filename (Options.get_module_name file) "h") :: List.concatMap (fun f -> let m = Options.get_module_name f in List.Tot.map (produce_nop_rule [to]) (maybe_krml_generated_h g m) ) all_files let c_to_o mtype o c = let oflag = match mtype with | HashingOptions.MakefileGMake -> "-o" | HashingOptions.MakefileNMake -> "/Fo:" in Printf.sprintf "%s %s %s" oflag o c let produce_output_types_o_rule mtype (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul:string) : FStar.All.ML (list rule_t) = if Deps.has_out_exprs g modul then let c = mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c" in let o = mk_filename (Printf.sprintf "%s_OutputTypes" modul) (oext mtype) in [{ ty = CC; from = c :: maybe_external_typedefs_h emit_output_types_defs g modul; to = o; args = c_to_o mtype o c; }] else let _ = FStar.IO.print_string (Printf.sprintf "%s has no output types\n" modul) in [] let produce_o_rule mtype (everparse_h: bool) (modul: string) : Tot rule_t = let c = mk_filename modul "c" in let o = mk_filename modul (oext mtype) in { ty = CC; from = ((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [c; mk_filename modul "h"]); to = o; args = c_to_o mtype o c; } let produce_wrapper_o_rule mtype (everparse_h: bool) (g: Deps.dep_graph) (modul: string) : Tot (list rule_t) = let wc = mk_filename (Printf.sprintf "%sWrapper" modul) "c" in let wh = mk_filename (Printf.sprintf "%sWrapper" modul) "h" in let wo = mk_filename (Printf.sprintf "%sWrapper" modul) (oext mtype) in let h = mk_filename modul "h" in if Deps.has_entrypoint g modul then [{ ty = CC; from =((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [wc; wh; h]); to = wo; args = c_to_o mtype wo wc; }] else [] let produce_static_assertions_o_rule mtype (everparse_h: bool) (g: Deps.dep_graph) (modul: string) : Tot (list rule_t) = let wc = mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c" in let wo = mk_filename (Printf.sprintf "%sStaticAssertions" modul) (oext mtype) in let h = mk_filename modul "h" in if Deps.has_static_assertions g modul then [{ ty = CC; from = ((if everparse_h then [mk_filename "EverParse" "h"] else []) `List.Tot.append` [wc; h]); to = wo; args = c_to_o mtype wo wc; }] else [] let produce_clang_format_rule (clang_format: bool) : Tot (list rule_t) = if clang_format then [{ ty = EverParse; from = []; to = mk_filename "" "clang-format"; args = "--__micro_step copy_clang_format"; }] else [] let produce_everparse_h_rule (everparse_h: bool) : Tot (list rule_t) = if everparse_h then [ { ty = EverParse; from = []; to = mk_filename "EverParseEndianness" "h"; args = "--__micro_step copy_everparse_h"; }; { ty = Nop; from = [mk_filename "EverParseEndianness" "h"]; to = mk_filename "EverParse" "h"; args = ""; } ] else [] noeq type produce_makefile_res = { rules: list rule_t; graph: Deps.dep_graph; all_files: list string; } let produce_makefile mtype (everparse_h: bool) (emit_output_types_defs: bool) (skip_o_rules: bool) (clang_format: bool) (files: list string) : FStar.All.ML produce_makefile_res = let g = Deps.build_dep_graph_from_list files in let all_files = Deps.collect_and_sort_dependencies_from_graph g files in let all_modules = List.map Options.get_module_name all_files in let rules = produce_everparse_h_rule everparse_h `List.Tot.append` produce_clang_format_rule clang_format `List.Tot.append` (if skip_o_rules then [] else List.Tot.concatMap (produce_wrapper_o_rule mtype everparse_h g) all_modules `List.Tot.append` List.Tot.concatMap (produce_static_assertions_o_rule mtype everparse_h g) all_modules `List.Tot.append` List.concatMap (produce_output_types_o_rule mtype emit_output_types_defs g) all_modules `List.Tot.append` List.Tot.map (produce_o_rule mtype everparse_h) all_modules ) `List.Tot.append` List.concatMap (produce_fst_rules emit_output_types_defs g clang_format) all_files `List.Tot.append` List.concatMap (produce_external_types_fsti_checked_rule g) all_modules `List.Tot.append` List.concatMap (produce_external_api_fsti_checked_rule g) all_modules `List.Tot.append` List.Tot.map (produce_fsti_checked_rule g) all_modules `List.Tot.append` List.map (produce_fst_checked_rule g) all_modules `List.Tot.append` List.Tot.concatMap (produce_external_types_krml_rule g) all_modules `List.Tot.append` List.Tot.concatMap (produce_external_api_krml_rule g) all_modules `List.Tot.append` List.map (produce_krml_rule g) all_modules `List.Tot.append` List.concatMap (produce_h_rules g clang_format) all_files `List.Tot.append` produce_config_fst_file_rule () in { graph = g; rules = rules; all_files = all_files; }
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
mtype: HashingOptions.makefile_type -> input_stream_binding: HashingOptions.input_stream_binding_t -> everparse_h: Prims.bool -> emit_output_types_defs: Prims.bool -> skip_o_rules: Prims.bool -> clang_format: Prims.bool -> files: Prims.list Prims.string -> FStar.All.ML Prims.unit
FStar.All.ML
[ "ml" ]
[]
[ "HashingOptions.makefile_type", "HashingOptions.input_stream_binding_t", "Prims.bool", "Prims.list", "Prims.string", "GenMakefile.rule_t", "Deps.dep_graph", "FStar.IO.close_write_file", "Prims.unit", "GenMakefile.oext", "FStar.IO.write_string", "FStar.Printf.sprintf", "FStar.String.concat", "FStar.List.Tot.Base.append", "FStar.List.map", "GenMakefile.mk_filename", "Options.get_module_name", "Prims.op_Equality", "FStar.List.concatMap", "GenMakefile.maybe_h", "Prims.Nil", "Prims.op_disEquality", "Deps.has_out_exprs", "Prims.Cons", "Deps.has_entrypoint", "Prims.op_AmpAmp", "Deps.has_static_assertions", "FStar.List.Tot.Base.map", "GenMakefile.print_make_rule", "GenMakefile.produce_makefile_res", "GenMakefile.produce_makefile", "FStar.IO.fd_write", "FStar.IO.open_write_file", "Options.get_makefile_name" ]
[]
false
true
false
false
false
let write_makefile mtype input_stream_binding (everparse_h: bool) (emit_output_types_defs: bool) (skip_o_rules: bool) (clang_format: bool) (files: list string) : FStar.All.ML unit =
let makefile = Options.get_makefile_name () in let file = FStar.IO.open_write_file makefile in let { graph = g ; rules = rules ; all_files = all_files } = produce_makefile mtype everparse_h emit_output_types_defs skip_o_rules clang_format files in FStar.IO.write_string file (String.concat "" (List.Tot.map (print_make_rule mtype everparse_h input_stream_binding) rules)); let write_all_ext_files (ext_cap ext: string) : FStar.All.ML unit = let ln = (((((if ext = "h" && everparse_h then [mk_filename "EverParse" "h"; mk_filename "EverParseEndianness" "h"] else []) `List.Tot.append` (if ext <> "h" then List.concatMap (fun f -> let m = Options.get_module_name f in if Deps.has_static_assertions g m then [mk_filename (Printf.sprintf "%sStaticAssertions" m) ext] else []) all_files else [])) `List.Tot.append` (List.concatMap (fun f -> let m = Options.get_module_name f in if Deps.has_entrypoint g m then [mk_filename (Printf.sprintf "%sWrapper" m) ext] else []) all_files)) `List.Tot.append` (if ext <> "h" then List.concatMap (fun f -> let m = Options.get_module_name f in if Deps.has_out_exprs g m then [mk_filename (Printf.sprintf "%s_OutputTypes" m) ext] else []) all_files else [])) `List.Tot.append` (if ext = "h" then List.concatMap (fun f -> let m = Options.get_module_name f in maybe_h emit_output_types_defs g m) all_files else [])) `List.Tot.append` (List.map (fun f -> mk_filename (Options.get_module_name f) ext) all_files) in FStar.IO.write_string file (Printf.sprintf "EVERPARSE_ALL_%s_FILES=%s\n" ext_cap (String.concat " " ln)) in write_all_ext_files "H" "h"; write_all_ext_files "C" "c"; write_all_ext_files "O" (oext mtype); FStar.IO.close_write_file file
false
GenMakefile.fst
GenMakefile.produce_fst_rules
val produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t)
val produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t)
let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c)
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 88, "end_line": 332, "start_col": 0, "start_line": 260 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else []
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
emit_output_types_defs: Prims.bool -> g: Deps.dep_graph -> clang_format: Prims.bool -> file: Prims.string -> FStar.All.ML (Prims.list GenMakefile.rule_t)
FStar.All.ML
[ "ml" ]
[]
[ "Prims.bool", "Deps.dep_graph", "Prims.string", "Prims.list", "Prims.Cons", "GenMakefile.rule_t", "FStar.List.Tot.Base.map", "GenMakefile.produce_nop_rule", "Prims.Nil", "FStar.List.Tot.Base.append", "GenMakefile.Mkrule_t", "GenMakefile.EverParse", "FStar.Printf.sprintf", "GenMakefile.mk_input_filename", "GenMakefile.mk_filename", "OS.file_exists", "Deps.has_entrypoint", "Deps.has_output_types", "Prims.op_Negation", "Deps.has_extern_types", "Deps.has_out_exprs", "Deps.has_static_assertions", "GenMakefile.has_external_types_fsti", "GenMakefile.has_external_api_fsti", "Options.get_module_name" ]
[]
false
true
false
false
false
let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) =
let modul = Options.get_module_name file in let first_fst :: other_fst = ((if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else []) `List.Tot.append` (if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [])) `List.Tot.append` [mk_filename modul "fst"; mk_filename modul "fsti"] in let produced_c = (((if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h" ] else []) `List.Tot.append` (if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: (if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else []) else [] else [])) `List.Tot.append` (if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [])) `List.Tot.append` (if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else []) in { ty = EverParse; from = ((if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else [])) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file) } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c)
false
GenMakefile.fst
GenMakefile.c_to_o
val c_to_o : mtype: HashingOptions.makefile_type -> o: Prims.string -> c: Prims.string -> Prims.string
let c_to_o mtype o c = let oflag = match mtype with | HashingOptions.MakefileGMake -> "-o" | HashingOptions.MakefileNMake -> "/Fo:" in Printf.sprintf "%s %s %s" oflag o c
{ "file_name": "src/3d/GenMakefile.fst", "git_rev": "00217c4a89f5ba56002ba9aa5b4a9d5903bfe9fa", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
{ "end_col": 37, "end_line": 418, "start_col": 0, "start_line": 413 }
module GenMakefile module OS = OS type rule_type = | EverParse | CC | Nop (* to simulate multiple-target rules *) type rule_t = { ty: rule_type; from: list string; to: string; args: string; } let input_dir = "$(EVERPARSE_INPUT_DIR)" let output_dir = "$(EVERPARSE_OUTPUT_DIR)" let oext = function | HashingOptions.MakefileGMake -> "o" | HashingOptions.MakefileNMake -> "obj" let print_make_rule mtype everparse_h input_stream_binding (r: rule_t) : Tot string = let rule = Printf.sprintf "%s : %s\n" r.to (String.concat " " r.from) in match r.ty with | Nop -> Printf.sprintf "%s\n" rule | _ -> let cmd = match r.ty with | EverParse -> Printf.sprintf "$(EVERPARSE_CMD) --odir %s" output_dir | CC -> let iopt = match mtype with | HashingOptions.MakefileGMake -> "-I" | HashingOptions.MakefileNMake -> "/I" in let inc = if everparse_h then "" else let ddd_home = "$(EVERPARSE_HOME)" `OS.concat` "src" `OS.concat` "3d" in let ddd_actions_home = ddd_home `OS.concat` "prelude" `OS.concat` (HashingOptions.string_of_input_stream_binding input_stream_binding) in Printf.sprintf "%s %s %s %s" iopt ddd_home iopt ddd_actions_home in let copt = match mtype with | HashingOptions.MakefileGMake -> "-c" | HashingOptions.MakefileNMake -> "/c" in Printf.sprintf "$(CC) $(CFLAGS) %s %s %s %s %s %s" iopt input_dir iopt output_dir inc copt in let rule = Printf.sprintf "%s\t%s %s\n\n" rule cmd r.args in rule let mk_input_filename (file: string) : Tot string = input_dir `OS.concat` OS.basename file let mk_filename (modul: string) (ext: string) : Tot string = output_dir `OS.concat` (Printf.sprintf "%s.%s" modul ext) let add_cfg_file_dep ext deps : FStar.All.ML (list string) = match Options.config_module_name () with | None -> deps | Some module_name -> deps `List.Tot.append` [mk_filename module_name ext] let produce_config_fst_file_rule () : FStar.All.ML (list rule_t) = match Options.config_module_name (), Options.get_config_file() with | Some module_name, Some cfg_file_name -> let fst_file_name = mk_filename module_name "fst" in let checked_file_name = mk_filename module_name "fst.checked" in let krml_file_name = mk_filename module_name "krml" in let fst_rule = { ty = EverParse; from = [cfg_file_name]; to = fst_file_name; args = "--__micro_step emit_config" } in let fst_checked_rule = { ty = EverParse; from = [fst_file_name]; to = checked_file_name; args = Printf.sprintf "--__micro_step verify %s" fst_file_name; } in let krml_rule = { ty = EverParse; from = [checked_file_name]; to = krml_file_name; args = Printf.sprintf "--__micro_step extract %s" fst_file_name; } in [fst_rule; fst_checked_rule; krml_rule] | _ -> [] let has_external_types_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = (Deps.has_output_types g modul || Deps.has_extern_types g modul) let maybe_external_types_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti.checked"] else [] let has_external_api_fsti (g: Deps.dep_graph) (modul: string) : Tot bool = Deps.has_extern_probe g modul || Deps.has_out_exprs g modul || Deps.has_extern_types g modul || Deps.has_extern_functions g modul let produce_external_api_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti = mk_filename modul "ExternalAPI.fsti" in [{ ty = EverParse; from = external_api_fsti :: (maybe_external_types_fsti_checked g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "ExternalAPI.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_api_fsti; }] let produce_external_types_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti = mk_filename modul "ExternalTypes.fsti" in [{ ty = EverParse; from = external_types_fsti :: List.Tot.map (fun m -> mk_filename m "ExternalTypes.fsti.checked") (Deps.dependencies g modul); to = mk_filename modul "ExternalTypes.fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" external_types_fsti; }] let maybe_external_api_fsti_checked (g: Deps.dep_graph) (modul: string) : Tot (list string) = if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti.checked"] else [] let external_deps (g: Deps.dep_graph) (modul: string) : Tot (list string) = maybe_external_types_fsti_checked g modul `List.Tot.append` maybe_external_api_fsti_checked g modul let produce_fsti_checked_rule (g: Deps.dep_graph) (modul: string) : Tot rule_t = let fsti = mk_filename modul "fsti" in { ty = EverParse; from = fsti :: (external_deps g modul `List.Tot.append` List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fsti.checked"; args = Printf.sprintf "--__micro_step verify %s" fsti; } let produce_fst_checked_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = let fst = mk_filename modul "fst" in { ty = EverParse; from = add_cfg_file_dep "fst.checked" (fst :: mk_filename modul "fsti.checked" :: List.Tot.map (fun m -> mk_filename m "fsti.checked") (Deps.dependencies g modul)); to = mk_filename modul "fst.checked"; args = Printf.sprintf "--__micro_step verify %s" fst; } let produce_external_types_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_types_fsti g modul) then [] else let external_types_fsti_checked = mk_filename modul "ExternalTypes.fsti.checked" in [{ ty = EverParse; from = external_types_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalTypes" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalTypes.fsti"); }] let produce_external_api_krml_rule (g: Deps.dep_graph) (modul: string) : list rule_t = if not (has_external_api_fsti g modul) then [] else let external_api_fsti_checked = mk_filename modul "ExternalAPI.fsti.checked" in [{ ty = EverParse; from = external_api_fsti_checked :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul); to = mk_filename (Printf.sprintf "%s_ExternalAPI" modul) "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "ExternalAPI.fsti"); }] let produce_krml_rule (g: Deps.dep_graph) (modul: string) : FStar.All.ML rule_t = { ty = EverParse; from = add_cfg_file_dep "fst.checked" (mk_filename modul "fst.checked" :: List.Tot.map (fun m -> mk_filename m "fst.checked") (Deps.dependencies g modul)); to = mk_filename modul "krml"; args = Printf.sprintf "--__micro_step extract %s" (mk_filename modul "fst"); } let produce_nop_rule (from: list string) (to: string) : Tot rule_t = { ty = Nop; from = from; to = to; args = ""; } let maybe_external_typedefs_h (emit_output_types_defs: bool) (g:Deps.dep_graph) (modul: string) : Tot (list string) = if (Deps.has_output_types g modul && not (Deps.has_extern_types g modul)) && emit_output_types_defs then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] let produce_fst_rules (emit_output_types_defs: bool) (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let modul = Options.get_module_name file in (* follow the order prescribed by Main.process_file *) (* fst* files generated by 3d (cf. Main.emit_fstar_code_for_interpreter) *) let first_fst :: other_fst = begin if has_external_types_fsti g modul then [mk_filename modul "ExternalTypes.fsti"] else [] end `List.Tot.append` begin if has_external_api_fsti g modul then [mk_filename modul "ExternalAPI.fsti"] else [] end `List.Tot.append` [ mk_filename modul "fst"; mk_filename modul "fsti"; ] in (* C files generated by 3d (as opposed to F*, cf. Main.emit_entrypoint) *) let produced_c = begin if Deps.has_entrypoint g modul then [ mk_filename (Printf.sprintf "%sWrapper" modul) "c"; mk_filename (Printf.sprintf "%sWrapper" modul) "h"; ] else [] end `List.Tot.append` begin if emit_output_types_defs then if Deps.has_output_types g modul then mk_filename (Printf.sprintf "%s_OutputTypesDefs" modul) "h" :: begin if not (Deps.has_extern_types g modul) then [mk_filename (Printf.sprintf "%s_ExternalTypedefs" modul) "h"] else [] end else [] else [] end `List.Tot.append` begin if Deps.has_out_exprs g modul then [mk_filename (Printf.sprintf "%s_OutputTypes" modul) "c"] else [] end `List.Tot.append` begin if Deps.has_static_assertions g modul then [mk_filename (Printf.sprintf "%sStaticAssertions" modul) "c"] else [] end in (* produce the actual rules *) { ty = EverParse; from = (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [mk_input_filename (Printf.sprintf "%s.copyright.txt" file)] else []) `List.Tot.append` [mk_input_filename file]; to = first_fst; args = Printf.sprintf "--no_batch %s" (mk_input_filename file); } :: List.Tot.map (produce_nop_rule [first_fst]) (other_fst `List.Tot.append` produced_c) let maybe_external_api_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "krml"] else [] let maybe_external_types_krml (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "krml"] else [] let maybe_external_types_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_types_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalTypes" m) "h"] else [] let maybe_external_api_h (g: Deps.dep_graph) (m: string) : Tot (list string) = if has_external_api_fsti g m then [mk_filename (Printf.sprintf "%s_ExternalAPI" m) "h"] else [] let maybe_krml_generated_h (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_external_types_h g m `List.Tot.append` maybe_external_api_h g m let maybe_h (emit_output_types_defs: bool) (g: Deps.dep_graph) (m: string) : Tot (list string) = maybe_krml_generated_h g m `List.Tot.append` maybe_external_typedefs_h emit_output_types_defs g m let produce_h_rules (g: Deps.dep_graph) (clang_format: bool) (file: string) : FStar.All.ML (list rule_t) = let all_files = Deps.collect_and_sort_dependencies_from_graph g [file] in let to = mk_filename (Options.get_module_name file) "c" in let copyright = mk_input_filename (Printf.sprintf "%s.3d.copyright.txt" (Options.get_module_name file)) in { ty = EverParse; from = add_cfg_file_dep "krml" ( (if clang_format then [mk_filename "" "clang-format"] else []) `List.Tot.append` (if OS.file_exists (Printf.sprintf "%s.copyright.txt" file) then [copyright] else []) `List.Tot.append` List.map (fun f -> mk_filename (Options.get_module_name f) "krml") all_files `List.Tot.append` List.concatMap (fun f -> let m = Options.get_module_name f in maybe_external_api_krml g m `List.Tot.append` maybe_external_types_krml g m ) all_files ) ; to = to; (* IMPORTANT: relies on the fact that KaRaMeL generates .c files BEFORE .h files *) args = Printf.sprintf "--__produce_c_from_existing_krml %s" (mk_input_filename file); } :: produce_nop_rule [to] (mk_filename (Options.get_module_name file) "h") :: List.concatMap (fun f -> let m = Options.get_module_name f in List.Tot.map (produce_nop_rule [to]) (maybe_krml_generated_h g m) ) all_files
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OS.fsti.checked", "Options.fsti.checked", "HashingOptions.fst.checked", "FStar.String.fsti.checked", "FStar.Printf.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked", "FStar.List.fst.checked", "FStar.IO.fst.checked", "FStar.All.fst.checked", "Deps.fsti.checked" ], "interface_file": true, "source_file": "GenMakefile.fst" }
[ { "abbrev": true, "full_module": "OS", "short_module": "OS" }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
mtype: HashingOptions.makefile_type -> o: Prims.string -> c: Prims.string -> Prims.string
Prims.Tot
[ "total" ]
[]
[ "HashingOptions.makefile_type", "Prims.string", "FStar.Printf.sprintf" ]
[]
false
false
false
true
false
let c_to_o mtype o c =
let oflag = match mtype with | HashingOptions.MakefileGMake -> "-o" | HashingOptions.MakefileNMake -> "/Fo:" in Printf.sprintf "%s %s %s" oflag o c
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.t_post
val t_post : Type
let t_post = state -> prop
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 55, "start_col": 0, "start_line": 55 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.state", "Prims.prop" ]
[]
false
false
false
true
true
let t_post =
state -> prop
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.t_pre
val t_pre : Type
let t_pre = state -> prop
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 58, "start_col": 0, "start_line": 58 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.state", "Prims.prop" ]
[]
false
false
false
true
true
let t_pre =
state -> prop
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.nonce
val nonce : a: Spec.Agile.Cipher.cipher_alg -> Type0
let nonce a = b:bytes { nonce_bound a (length b) }
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 50, "end_line": 57, "start_col": 0, "start_line": 57 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key let block_length (a:cipher_alg) = match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64 let block a = lbytes (block_length a) /// Smaller bound than for AES-GCM; no IV reduction. let nonce_bound (a: cipher_alg) (n_len: nat): Type0 = match a with | AES128 | AES256 -> n_len <= block_length a | CHACHA20 -> n_len == 12
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Lib.ByteSequence.bytes", "Spec.Agile.Cipher.nonce_bound", "Lib.Sequence.length", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC" ]
[]
false
false
false
true
true
let nonce a =
b: bytes{nonce_bound a (length b)}
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.t_wp
val t_wp : Type
let t_wp = t_post -> t_pre
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 26, "end_line": 61, "start_col": 0, "start_line": 61 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
Type
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.ValeVC.t_post", "OPLSS2021.ValeVC.t_pre" ]
[]
false
false
false
true
true
let t_wp =
t_post -> t_pre
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.ctr
val ctr : Type0
let ctr = size_nat
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 59, "start_col": 0, "start_line": 59 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key let block_length (a:cipher_alg) = match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64 let block a = lbytes (block_length a) /// Smaller bound than for AES-GCM; no IV reduction. let nonce_bound (a: cipher_alg) (n_len: nat): Type0 = match a with | AES128 | AES256 -> n_len <= block_length a | CHACHA20 -> n_len == 12 let nonce a = b:bytes { nonce_bound a (length b) }
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
Type0
Prims.Tot
[ "total" ]
[]
[ "Lib.IntTypes.size_nat" ]
[]
false
false
false
true
true
let ctr =
size_nat
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.t_lemma
val t_lemma : pre: Prims.prop -> post: Prims.prop -> Type0
let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post)
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 45, "end_line": 75, "start_col": 0, "start_line": 74 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
pre: Prims.prop -> post: Prims.prop -> Type0
Prims.Tot
[ "total" ]
[]
[ "Prims.prop", "Prims.unit", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
false
false
false
true
true
let t_lemma (pre post: prop) =
unit -> Lemma (requires pre) (ensures post)
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.vc_sound'
val vc_sound' (cs: list code) (qcs: with_wps cs) : has_wp (Block cs) (vc_gen cs qcs)
val vc_sound' (cs: list code) (qcs: with_wps cs) : has_wp (Block cs) (vc_gen cs qcs)
let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 19, "end_line": 142, "start_col": 0, "start_line": 140 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
cs: Prims.list OPLSS2021.Vale.code -> qcs: OPLSS2021.ValeVC.with_wps cs -> OPLSS2021.ValeVC.has_wp (OPLSS2021.Vale.Block cs) (OPLSS2021.ValeVC.vc_gen cs qcs)
Prims.Tot
[ "total" ]
[]
[ "Prims.list", "OPLSS2021.Vale.code", "OPLSS2021.ValeVC.with_wps", "OPLSS2021.ValeVC.vc_sound", "OPLSS2021.ValeVC.has_wp", "OPLSS2021.Vale.Block", "OPLSS2021.ValeVC.vc_gen" ]
[]
false
false
false
false
false
let vc_sound' (cs: list code) (qcs: with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) =
vc_sound cs qcs
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.inst_Move
val inst_Move (dst src: operand) : with_wp (Ins (Mov64 dst src))
val inst_Move (dst src: operand) : with_wp (Ins (Mov64 dst src))
let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src)
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 68, "end_line": 167, "start_col": 0, "start_line": 166 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> OPLSS2021.ValeVC.with_wp (OPLSS2021.Vale.Ins (OPLSS2021.Vale.Mov64 dst src))
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.ValeVC.QProc", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Mov64", "OPLSS2021.ValeVC.wp_Move", "OPLSS2021.ValeVC.hasWp_Move", "OPLSS2021.ValeVC.with_wp" ]
[]
false
false
false
false
false
let inst_Move (dst src: operand) : with_wp (Ins (Mov64 dst src)) =
QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src)
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.aes_alg_of_alg
val aes_alg_of_alg : a: Spec.Agile.Cipher.cipher_alg{a = Spec.Agile.Cipher.AES128 \/ a = Spec.Agile.Cipher.AES256} -> Spec.AES.variant
let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 29, "end_line": 30, "start_col": 0, "start_line": 27 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg{a = Spec.Agile.Cipher.AES128 \/ a = Spec.Agile.Cipher.AES256} -> Spec.AES.variant
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Prims.l_or", "Prims.b2t", "Prims.op_Equality", "Spec.Agile.Cipher.AES128", "Spec.Agile.Cipher.AES256", "Spec.AES.AES128", "Spec.AES.AES256", "Spec.AES.variant" ]
[]
false
false
false
false
false
let aes_alg_of_alg (a: cipher_alg{a = AES128 \/ a = AES256}) =
match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.vc_sound
val vc_sound (cs: list code) (qcs: with_wps cs) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN)
val vc_sound (cs: list code) (qcs: with_wps cs) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN)
let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 27, "end_line": 138, "start_col": 0, "start_line": 121 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
cs: Prims.list OPLSS2021.Vale.code -> qcs: OPLSS2021.ValeVC.with_wps cs -> k: (_: OPLSS2021.Vale.state -> Prims.prop) -> s0: OPLSS2021.Vale.state -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "Prims.list", "OPLSS2021.Vale.code", "OPLSS2021.ValeVC.with_wps", "OPLSS2021.Vale.state", "Prims.prop", "FStar.Pervasives.Native.Mktuple2", "OPLSS2021.Vale.fuel", "OPLSS2021.ValeVC.with_wp", "OPLSS2021.Vale.lemma_merge", "FStar.Pervasives.Native.tuple2", "OPLSS2021.ValeVC.vc_sound", "OPLSS2021.ValeVC.__proj__QProc__item__hasWp", "OPLSS2021.ValeVC.vc_gen", "OPLSS2021.ValeVC.t_lemma", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Block", "FStar.Pervasives.Native.Some" ]
[ "recursion" ]
false
false
false
false
false
let rec vc_sound (cs: list code) (qcs: with_wps cs) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) =
match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let sM, fM = qc.hasWp (vc_gen cs' qcs k) s0 in let sN, fN = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.vc_gen
val vc_gen (cs: list code) (qcs: with_wps cs) (k: t_post) : Tot (state -> Tot prop (decreases qcs))
val vc_gen (cs: list code) (qcs: with_wps cs) (k: t_post) : Tot (state -> Tot prop (decreases qcs))
let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0)
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 33, "end_line": 118, "start_col": 0, "start_line": 105 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
cs: Prims.list OPLSS2021.Vale.code -> qcs: OPLSS2021.ValeVC.with_wps cs -> k: OPLSS2021.ValeVC.t_post -> _: OPLSS2021.Vale.state -> Prims.Tot Prims.prop
Prims.Tot
[ "total", "" ]
[]
[ "Prims.list", "OPLSS2021.Vale.code", "OPLSS2021.ValeVC.with_wps", "OPLSS2021.ValeVC.t_post", "OPLSS2021.Vale.state", "OPLSS2021.ValeVC.with_wp", "OPLSS2021.ValeVC.__proj__QProc__item__wp", "OPLSS2021.ValeVC.vc_gen", "Prims.__proj__Cons__item__tl", "Prims.prop", "OPLSS2021.ValeVC.t_lemma", "Prims.l_and", "Prims.l_imp" ]
[ "recursion" ]
false
false
false
false
true
let rec vc_gen (cs: list code) (qcs: with_wps cs) (k: t_post) : Tot (state -> Tot prop (decreases qcs)) =
fun s0 -> match qcs with | QEmpty -> k s0 | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ (post ==> vc_gen cs qcs k s0)
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.inst_Add
val inst_Add (dst src: operand) : with_wp (Ins (Add64 dst src))
val inst_Add (dst src: operand) : with_wp (Ins (Add64 dst src))
let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src)
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 66, "end_line": 188, "start_col": 0, "start_line": 187 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> OPLSS2021.ValeVC.with_wp (OPLSS2021.Vale.Ins (OPLSS2021.Vale.Add64 dst src))
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.ValeVC.QProc", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Add64", "OPLSS2021.ValeVC.wp_Add", "OPLSS2021.ValeVC.hasWp_Add", "OPLSS2021.ValeVC.with_wp" ]
[]
false
false
false
false
false
let inst_Add (dst src: operand) : with_wp (Ins (Add64 dst src)) =
QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src)
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.nonce_bound
val nonce_bound (a: cipher_alg) (n_len: nat) : Type0
val nonce_bound (a: cipher_alg) (n_len: nat) : Type0
let nonce_bound (a: cipher_alg) (n_len: nat): Type0 = match a with | AES128 | AES256 -> n_len <= block_length a | CHACHA20 -> n_len == 12
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 27, "end_line": 55, "start_col": 0, "start_line": 52 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key let block_length (a:cipher_alg) = match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64 let block a = lbytes (block_length a)
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> n_len: Prims.nat -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Spec.Agile.Cipher.block_length", "Prims.eq2", "Prims.int" ]
[]
false
false
false
true
true
let nonce_bound (a: cipher_alg) (n_len: nat) : Type0 =
match a with | AES128 | AES256 -> n_len <= block_length a | CHACHA20 -> n_len == 12
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.normal_steps
val normal_steps:list string
val normal_steps:list string
let normal_steps : list string = [ `%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state; ]
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 202, "start_col": 0, "start_line": 194 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src [@@qattr] let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src) //////////////////////////////////////////////////////////////////////////////// //Running the VC generator using the F* normalizer ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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.list Prims.string
Prims.Tot
[ "total" ]
[]
[ "Prims.Cons", "Prims.string", "Prims.Nil" ]
[]
false
false
false
true
false
let normal_steps:list string =
[`%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state]
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.wp_Move
val wp_Move (dst src: operand) (k: (state -> prop)) (s0: state) : prop
val wp_Move (dst src: operand) (k: (state -> prop)) (s0: state) : prop
let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM )
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 5, "end_line": 157, "start_col": 0, "start_line": 151 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> k: (_: OPLSS2021.Vale.state -> Prims.prop) -> s0: OPLSS2021.Vale.state -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.Vale.state", "Prims.prop", "Prims.l_and", "Prims.b2t", "OPLSS2021.Vale.uu___is_OReg", "Prims.l_Forall", "OPLSS2021.Vale.nat64", "Prims.l_imp", "Prims.eq2", "OPLSS2021.Vale.eval_operand", "OPLSS2021.Vale.update_reg", "OPLSS2021.Vale.__proj__OReg__item__r" ]
[]
false
false
false
true
true
let wp_Move (dst src: operand) (k: (state -> prop)) (s0: state) : prop =
OReg? dst /\ (forall (x: nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM)
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.normal
val normal (x: Type0) : Type0
val normal (x: Type0) : Type0
let normal (x:Type0) : Type0 = norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 34, "end_line": 212, "start_col": 0, "start_line": 205 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src [@@qattr] let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src) //////////////////////////////////////////////////////////////////////////////// //Running the VC generator using the F* normalizer //////////////////////////////////////////////////////////////////////////////// unfold let normal_steps : list string = [ `%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state; ]
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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: Type0 -> Type0
Prims.Tot
[ "total" ]
[]
[ "FStar.Pervasives.norm", "Prims.Cons", "FStar.Pervasives.norm_step", "FStar.Pervasives.nbe", "FStar.Pervasives.iota", "FStar.Pervasives.zeta", "FStar.Pervasives.simplify", "FStar.Pervasives.primops", "FStar.Pervasives.delta_attr", "Prims.string", "Prims.Nil", "FStar.Pervasives.delta_only", "OPLSS2021.ValeVC.normal_steps" ]
[]
false
false
false
true
true
let normal (x: Type0) : Type0 =
norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.hasWp_Move
val hasWp_Move (dst src: operand) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM)
val hasWp_Move (dst src: operand) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM)
let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 25, "end_line": 163, "start_col": 0, "start_line": 159 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> k: (_: OPLSS2021.Vale.state -> Prims.prop) -> s0: OPLSS2021.Vale.state -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.Vale.state", "Prims.prop", "OPLSS2021.Vale.lemma_Move", "FStar.Pervasives.Native.tuple2", "OPLSS2021.Vale.fuel", "OPLSS2021.ValeVC.wp_Move", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Mov64", "FStar.Pervasives.Native.Some" ]
[]
false
false
false
false
false
let hasWp_Move (dst src: operand) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) =
lemma_Move s0 dst src
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.key
val key : a: Spec.Agile.Cipher.cipher_alg -> Type0
let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 33, "end_line": 42, "start_col": 0, "start_line": 39 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Spec.AES.aes_key", "Spec.Agile.Cipher.aes_alg_of_alg", "Spec.Chacha20.key" ]
[]
false
false
false
true
true
let key (a: cipher_alg) =
match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.key_length
val key_length (a: cipher_alg) : size_nat
val key_length (a: cipher_alg) : size_nat
let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 38, "end_line": 37, "start_col": 0, "start_line": 34 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> Lib.IntTypes.size_nat
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Spec.AES.key_size", "Spec.Agile.Cipher.aes_alg_of_alg", "Spec.Chacha20.size_key", "Lib.IntTypes.size_nat" ]
[]
false
false
false
true
false
let key_length (a: cipher_alg) : size_nat =
match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.wp_Add
val wp_Add (dst src: operand) (k: (state -> prop)) (s0: state) : prop
val wp_Add (dst src: operand) (k: (state -> prop)) (s0: state) : prop
let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM )
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 3, "end_line": 178, "start_col": 0, "start_line": 173 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> k: (_: OPLSS2021.Vale.state -> Prims.prop) -> s0: OPLSS2021.Vale.state -> Prims.prop
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.Vale.state", "Prims.prop", "Prims.l_and", "Prims.b2t", "OPLSS2021.Vale.uu___is_OReg", "Prims.op_LessThan", "Prims.op_Addition", "OPLSS2021.Vale.eval_operand", "OPLSS2021.Vale.pow2_64", "Prims.l_Forall", "OPLSS2021.Vale.nat64", "Prims.l_imp", "Prims.eq2", "Prims.int", "OPLSS2021.Vale.update_reg", "OPLSS2021.Vale.__proj__OReg__item__r" ]
[]
false
false
false
true
true
let wp_Add (dst src: operand) (k: (state -> prop)) (s0: state) : prop =
OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x: nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM)
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.inst_Triple
val inst_Triple:with_wps codes_Triple
val inst_Triple:with_wps codes_Triple
let inst_Triple : with_wps codes_Triple = //A typeclass instance for our program QSeq (inst_Move (OReg Rbx) (OReg Rax)) ( QSeq (inst_Add (OReg Rax) (OReg Rbx)) ( QSeq (inst_Add (OReg Rbx) (OReg Rax)) ( QEmpty)))
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 11, "end_line": 236, "start_col": 0, "start_line": 231 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src [@@qattr] let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src) //////////////////////////////////////////////////////////////////////////////// //Running the VC generator using the F* normalizer //////////////////////////////////////////////////////////////////////////////// unfold let normal_steps : list string = [ `%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state; ] unfold let normal (x:Type0) : Type0 = norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x let vc_sound_norm (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = vc_sound cs qcs k s0 //////////////////////////////////////////////////////////////////////////////// // Verifying a simple program ////////////////////////////////////////////////////////////////////////////////
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
OPLSS2021.ValeVC.with_wps OPLSS2021.Vale.codes_Triple
Prims.Tot
[ "total" ]
[]
[ "OPLSS2021.ValeVC.QSeq", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Mov64", "OPLSS2021.Vale.OReg", "OPLSS2021.Vale.Rbx", "OPLSS2021.Vale.Rax", "Prims.Cons", "OPLSS2021.Vale.code", "OPLSS2021.Vale.Add64", "Prims.Nil", "OPLSS2021.ValeVC.inst_Move", "OPLSS2021.ValeVC.inst_Add", "OPLSS2021.ValeVC.QEmpty" ]
[]
false
false
false
true
false
let inst_Triple:with_wps codes_Triple =
QSeq (inst_Move (OReg Rbx) (OReg Rax)) (QSeq (inst_Add (OReg Rax) (OReg Rbx)) (QSeq (inst_Add (OReg Rbx) (OReg Rax)) (QEmpty)))
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.hasWp_Add
val hasWp_Add (dst src: operand) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM)
val hasWp_Add (dst src: operand) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM)
let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 184, "start_col": 0, "start_line": 180 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM )
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
dst: OPLSS2021.Vale.operand -> src: OPLSS2021.Vale.operand -> k: (_: OPLSS2021.Vale.state -> Prims.prop) -> s0: OPLSS2021.Vale.state -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.operand", "OPLSS2021.Vale.state", "Prims.prop", "OPLSS2021.Vale.lemma_Add", "FStar.Pervasives.Native.tuple2", "OPLSS2021.Vale.fuel", "OPLSS2021.ValeVC.wp_Add", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Ins", "OPLSS2021.Vale.Add64", "FStar.Pervasives.Native.Some" ]
[]
false
false
false
false
false
let hasWp_Add (dst src: operand) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) =
lemma_Add s0 dst src
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.block
val block : a: Spec.Agile.Cipher.cipher_alg -> Type0
let block a = lbytes (block_length a)
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 37, "end_line": 49, "start_col": 0, "start_line": 49 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key let block_length (a:cipher_alg) = match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> Type0
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Lib.ByteSequence.lbytes", "Spec.Agile.Cipher.block_length" ]
[]
false
false
false
true
true
let block a =
lbytes (block_length a)
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.block_length
val block_length : a: Spec.Agile.Cipher.cipher_alg -> Prims.int
let block_length (a:cipher_alg) = match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 18, "end_line": 47, "start_col": 0, "start_line": 44 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> Prims.int
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Prims.int" ]
[]
false
false
false
true
false
let block_length (a: cipher_alg) =
match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.vc_sound_norm
val vc_sound_norm (cs: list code) (qcs: with_wps cs) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN)
val vc_sound_norm (cs: list code) (qcs: with_wps cs) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN)
let vc_sound_norm (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = vc_sound cs qcs k s0
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 24, "end_line": 224, "start_col": 0, "start_line": 214 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src [@@qattr] let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src) //////////////////////////////////////////////////////////////////////////////// //Running the VC generator using the F* normalizer //////////////////////////////////////////////////////////////////////////////// unfold let normal_steps : list string = [ `%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state; ] unfold let normal (x:Type0) : Type0 = norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
cs: Prims.list OPLSS2021.Vale.code -> qcs: OPLSS2021.ValeVC.with_wps cs -> k: (_: OPLSS2021.Vale.state -> Prims.prop) -> s0: OPLSS2021.Vale.state -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "Prims.list", "OPLSS2021.Vale.code", "OPLSS2021.ValeVC.with_wps", "OPLSS2021.Vale.state", "Prims.prop", "OPLSS2021.ValeVC.vc_sound", "FStar.Pervasives.Native.tuple2", "OPLSS2021.Vale.fuel", "OPLSS2021.ValeVC.normal", "OPLSS2021.ValeVC.vc_gen", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Block", "FStar.Pervasives.Native.Some" ]
[]
false
false
false
false
false
let vc_sound_norm (cs: list code) (qcs: with_wps cs) (k: (state -> prop)) (s0: state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) =
vc_sound cs qcs k s0
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.lemma_Triple_opt
val lemma_Triple_opt (s0: state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` (update_state Rbx sM (update_state Rax sM s0)))
val lemma_Triple_opt (s0: state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` (update_state Rbx sM (update_state Rax sM s0)))
let lemma_Triple_opt (s0:state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` update_state Rbx sM (update_state Rax sM s0)) = // Optimized VC generation: vc_sound_norm codes_Triple inst_Triple (fun sM -> sM Rbx == 3 * s0 Rax /\ state_eq sM (update_state Rax sM (update_state Rbx sM s0))) s0
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 6, "end_line": 275, "start_col": 0, "start_line": 261 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src [@@qattr] let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src) //////////////////////////////////////////////////////////////////////////////// //Running the VC generator using the F* normalizer //////////////////////////////////////////////////////////////////////////////// unfold let normal_steps : list string = [ `%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state; ] unfold let normal (x:Type0) : Type0 = norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x let vc_sound_norm (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = vc_sound cs qcs k s0 //////////////////////////////////////////////////////////////////////////////// // Verifying a simple program //////////////////////////////////////////////////////////////////////////////// [@@qattr] let inst_Triple : with_wps codes_Triple = //A typeclass instance for our program QSeq (inst_Move (OReg Rbx) (OReg Rax)) ( QSeq (inst_Add (OReg Rax) (OReg Rbx)) ( QSeq (inst_Add (OReg Rbx) (OReg Rax)) ( QEmpty))) (* procedure Triple() modifies rax; rbx; requires rax < 100; ensures rbx == 3 * old(rax); { Mov(rbx, rax); Add(rax, rbx); Add(rbx, rax); } *) [@@qattr] let state_eq (s0 s1:state) : Pure Type0 (requires True) (ensures fun b -> b ==> s0 `feq` s1) = s0 Rax == s1 Rax /\ s0 Rbx == s1 Rbx /\ s0 Rcx == s1 Rcx /\ s0 Rdx == s1 Rdx
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s0: OPLSS2021.Vale.state -> Prims.Pure (OPLSS2021.Vale.state * OPLSS2021.Vale.fuel)
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.state", "OPLSS2021.ValeVC.vc_sound_norm", "OPLSS2021.Vale.codes_Triple", "OPLSS2021.ValeVC.inst_Triple", "Prims.l_and", "Prims.eq2", "Prims.int", "OPLSS2021.Vale.Rbx", "FStar.Mul.op_Star", "OPLSS2021.Vale.Rax", "OPLSS2021.ValeVC.state_eq", "OPLSS2021.Vale.update_state", "Prims.prop", "FStar.Pervasives.Native.tuple2", "OPLSS2021.Vale.fuel", "Prims.b2t", "Prims.op_LessThan", "FStar.Pervasives.Native.option", "OPLSS2021.Vale.eval_code", "OPLSS2021.Vale.Block", "FStar.Pervasives.Native.Some", "FStar.FunctionalExtensionality.feq", "OPLSS2021.Vale.reg", "OPLSS2021.Vale.nat64" ]
[]
false
false
false
false
false
let lemma_Triple_opt (s0: state) : Pure (state & fuel) (requires s0 Rax < 100) (ensures fun (sM, f0) -> eval_code (Block codes_Triple) f0 s0 == Some sM /\ sM Rbx == 3 * s0 Rax /\ sM `feq` (update_state Rbx sM (update_state Rax sM s0))) =
vc_sound_norm codes_Triple inst_Triple (fun sM -> sM Rbx == 3 * s0 Rax /\ state_eq sM (update_state Rax sM (update_state Rbx sM s0))) s0
false
OPLSS2021.ValeVC.fst
OPLSS2021.ValeVC.state_eq
val state_eq (s0 s1: state) : Pure Type0 (requires True) (ensures fun b -> b ==> s0 `feq` s1)
val state_eq (s0 s1: state) : Pure Type0 (requires True) (ensures fun b -> b ==> s0 `feq` s1)
let state_eq (s0 s1:state) : Pure Type0 (requires True) (ensures fun b -> b ==> s0 `feq` s1) = s0 Rax == s1 Rax /\ s0 Rbx == s1 Rbx /\ s0 Rcx == s1 Rcx /\ s0 Rdx == s1 Rdx
{ "file_name": "examples/oplss2021/OPLSS2021.ValeVC.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 18, "end_line": 259, "start_col": 0, "start_line": 252 }
(* Copyright 2008-2019 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. Authors: C. Hawblitzel, N. Swamy *) module OPLSS2021.ValeVC open OPLSS2021.Vale open FStar.FunctionalExtensionality open FStar.Mul ///////////////////////////////////////////////////////////////// // Now, we're going to define a verification-condition generator // // The main idea is that we're going to: // // 1. define a kind of typeclass, that associates with a // piece of code a weakest-precondition rule for it // // 2. Define a WP-generator that computes WPs for each of the // control constructs of the language, given a program // represented as the raw code packaged with their typeclass // instances for computing their WPs // // 3. Run the WP generator on F*'s normalizer and feed to Z3 // the resulting verification condition ///////////////////////////////////////////////////////////////// (* This is a highly-simplified model of Vale/F*, based on Section 3.1-3.3 of the paper of the POPL '19 paper. It is derived from the QuickRegs1 code in the popl-artifact-submit branch of Vale. *) /// We use this tag to mark certain definitions /// and control normalization based on it irreducible let qattr = () [@@qattr] let t_post = state -> prop [@@qattr] let t_pre = state -> prop /// t_wp: The type of weakest preconditions let t_wp = t_post -> t_pre /// c `has_wp` wp: The main judgment in our program logic let has_wp (c:code) (wp:t_wp) : Type = k:t_post -> //for any post-condition s0:state -> //and initial state Pure (state & fuel) (requires wp k s0) //Given the precondition (ensures fun (sM, f0) -> //we can compute the fuel f0 needed so that eval_code c f0 s0 == Some sM /\ //eval_code with that fuel returns sM k sM) //and the post-condition is true on sM /// An abbreviation for a thunked lemma let t_lemma (pre:prop) (post:prop) = unit -> Lemma (requires pre) (ensures post) /// `with_wp` : A typeclass for code packaged with its wp [@@qattr] noeq type with_wp : code -> Type = | QProc: c:code -> wp:t_wp -> hasWp:has_wp c wp -> with_wp c /// `with_wps`: A typclass for lists of code values packages with their wps noeq type with_wps : list code -> Type = | QEmpty: //empty list with_wps [] | QSeq: //cons #c:code -> #cs:list code -> hd:with_wp c -> tl:with_wps cs -> with_wps (c::cs) | QLemma: //augmenting an instruction sequence with a lemma #cs:list code -> pre:prop -> post:prop -> t_lemma pre post -> with_wps cs -> with_wps cs [@@qattr] let rec vc_gen (cs:list code) (qcs:with_wps cs) (k:t_post) : Tot (state -> Tot prop (decreases qcs)) = fun s0 -> match qcs with | QEmpty -> k s0 //no instructions; prove the postcondition right away | QSeq qc qcs -> qc.wp (vc_gen (Cons?.tl cs) qcs k) s0 | QLemma pre post _ qcs -> pre /\ //prove the precondition of the lemma (post ==> vc_gen cs qcs k s0) //and assume its postcondition to verify the progra /// The vc-generator is sound let rec vc_sound (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires vc_gen cs qcs k s0) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = match qcs with | QEmpty -> (s0, 0) | QSeq qc qcs -> let Cons c cs' = cs in let (sM, fM) = qc.hasWp (vc_gen cs' qcs k) s0 in let (sN, fN) = vc_sound cs' qcs k sM in let fN' = lemma_merge c cs' s0 fM sM fN sN in (sN, fN') | QLemma pre post lem qcs' -> lem (); vc_sound cs qcs' k s0 let vc_sound' (cs:list code) (qcs:with_wps cs) : has_wp (Block cs) (vc_gen cs qcs) = vc_sound cs qcs (*** Instances of with_wp ***) //////////////////////////////////////////////////////////////////////////////// //Instance for Mov //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand src s0 ==> k sM ) let hasWp_Move (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Move dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Mov64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Move s0 dst src [@@qattr] let inst_Move (dst:operand) (src:operand) : with_wp (Ins (Mov64 dst src)) = QProc (Ins (Mov64 dst src)) (wp_Move dst src) (hasWp_Move dst src) //////////////////////////////////////////////////////////////////////////////// //Instance for Add //////////////////////////////////////////////////////////////////////////////// [@@qattr] let wp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : prop = OReg? dst /\ eval_operand dst s0 + eval_operand src s0 < pow2_64 /\ (forall (x:nat64). let sM = update_reg s0 (OReg?.r dst) x in eval_operand dst sM == eval_operand dst s0 + eval_operand src s0 ==> k sM ) let hasWp_Add (dst:operand) (src:operand) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires wp_Add dst src k s0) (ensures fun (sM, f0) -> eval_code (Ins (Add64 dst src)) f0 s0 == Some sM /\ k sM) = lemma_Add s0 dst src [@@qattr] let inst_Add (dst:operand) (src:operand) : with_wp (Ins (Add64 dst src)) = QProc (Ins (Add64 dst src)) (wp_Add dst src) (hasWp_Add dst src) //////////////////////////////////////////////////////////////////////////////// //Running the VC generator using the F* normalizer //////////////////////////////////////////////////////////////////////////////// unfold let normal_steps : list string = [ `%OReg?; `%OReg?.r; `%QProc?.wp; `%eval_operand; `%update_reg; `%update_state; ] unfold let normal (x:Type0) : Type0 = norm [nbe; iota; zeta; simplify; primops; delta_attr [`%qattr]; delta_only normal_steps] x let vc_sound_norm (cs:list code) (qcs:with_wps cs) (k:state -> prop) (s0:state) : Pure (state & fuel) (requires normal (vc_gen cs qcs k s0)) (ensures fun (sN, fN) -> eval_code (Block cs) fN s0 == Some sN /\ k sN) = vc_sound cs qcs k s0 //////////////////////////////////////////////////////////////////////////////// // Verifying a simple program //////////////////////////////////////////////////////////////////////////////// [@@qattr] let inst_Triple : with_wps codes_Triple = //A typeclass instance for our program QSeq (inst_Move (OReg Rbx) (OReg Rax)) ( QSeq (inst_Add (OReg Rax) (OReg Rbx)) ( QSeq (inst_Add (OReg Rbx) (OReg Rax)) ( QEmpty))) (* procedure Triple() modifies rax; rbx; requires rax < 100; ensures rbx == 3 * old(rax); { Mov(rbx, rax); Add(rax, rbx); Add(rbx, rax); } *)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "OPLSS2021.Vale.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.FunctionalExtensionality.fsti.checked" ], "interface_file": false, "source_file": "OPLSS2021.ValeVC.fst" }
[ { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.FunctionalExtensionality", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021.Vale", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "OPLSS2021", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": 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
s0: OPLSS2021.Vale.state -> s1: OPLSS2021.Vale.state -> Prims.Pure Type0
Prims.Pure
[]
[]
[ "OPLSS2021.Vale.state", "Prims.l_and", "Prims.eq2", "OPLSS2021.Vale.nat64", "OPLSS2021.Vale.Rax", "OPLSS2021.Vale.Rbx", "OPLSS2021.Vale.Rcx", "OPLSS2021.Vale.Rdx", "Prims.l_True", "Prims.l_imp", "FStar.FunctionalExtensionality.feq", "OPLSS2021.Vale.reg" ]
[]
false
false
false
false
true
let state_eq (s0 s1: state) : Pure Type0 (requires True) (ensures fun b -> b ==> s0 `feq` s1) =
s0 Rax == s1 Rax /\ s0 Rbx == s1 Rbx /\ s0 Rcx == s1 Rcx /\ s0 Rdx == s1 Rdx
false
Spec.Agile.Cipher.fsti
Spec.Agile.Cipher.ctr_stream
val ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len}
val ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len}
let ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat): b:bytes { length b = len } = // JP: useful? be overconservative and always do + 1? would necessitate a // little bit of reasoning on the implementation side, perhaps better to have // a tighter bound here let n_blocks: n:nat { n * block_length a >= len } = if len % block_length a = 0 then len / block_length a else len / block_length a + 1 in let (), blocks = generate_blocks (block_length a) max_size_t n_blocks (fun _ -> unit) // extra cruft; no accumulator here (fun i _ -> (), ctr_block a k iv i ) () in Seq.slice blocks 0 len
{ "file_name": "specs/Spec.Agile.Cipher.fsti", "git_rev": "eb1badfa34c70b0bbe0fe24fe0f49fb1295c7872", "git_url": "https://github.com/project-everest/hacl-star.git", "project_name": "hacl-star" }
{ "end_col": 24, "end_line": 90, "start_col": 0, "start_line": 70 }
module Spec.Agile.Cipher open FStar.Mul open Lib.IntTypes open Lib.Sequence open Lib.ByteSequence #reset-options "--z3rlimit 20 --max_fuel 0 --max_ifuel 1" /// This module is concerned with defining an agile stream cipher, i.e. a /// function that given: a key; an iv (nonce); a counter, produces a fresh /// block. We leave details of key expansion to the ``.fst``, or possibly even /// to the low-level implementation. val force_flush_interleaving: unit /// Definitions /// ----------- type cipher_alg = | AES128 | AES256 | CHACHA20 /// The AES spec itself is agile; this is the same nested agility technique used /// for SHA2 vs. MD. let aes_alg_of_alg (a: cipher_alg { a = AES128 \/ a = AES256 }) = match a with | AES128 -> Spec.AES.AES128 | AES256 -> Spec.AES.AES256 /// Trying to enforce conventions: lengths for nats (spec); len for machine /// integers (runtime). let key_length (a: cipher_alg): size_nat = match a with | AES128 | AES256 -> Spec.AES.key_size (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.size_key let key (a: cipher_alg) = match a with | AES128 | AES256 -> Spec.AES.aes_key (aes_alg_of_alg a) | CHACHA20 -> Spec.Chacha20.key let block_length (a:cipher_alg) = match a with | AES128 | AES256 -> 16 | CHACHA20 -> 64 let block a = lbytes (block_length a) /// Smaller bound than for AES-GCM; no IV reduction. let nonce_bound (a: cipher_alg) (n_len: nat): Type0 = match a with | AES128 | AES256 -> n_len <= block_length a | CHACHA20 -> n_len == 12 let nonce a = b:bytes { nonce_bound a (length b) } let ctr = size_nat /// The stream cipher /// ----------------- /// One block of pseudo-random bytes. val ctr_block (a: cipher_alg) (k: key a) (iv: nonce a) (c: ctr): block a /// A stream of pseudo-random bytes, starting from counter zero. The length is
{ "checked_file": "/", "dependencies": [ "Spec.Chacha20.fst.checked", "Spec.AES.fst.checked", "prims.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked" ], "interface_file": false, "source_file": "Spec.Agile.Cipher.fsti" }
[ { "abbrev": false, "full_module": "Lib.ByteSequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "Spec.Agile", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 0, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": false, "z3cliopt": [], "z3refresh": false, "z3rlimit": 20, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
a: Spec.Agile.Cipher.cipher_alg -> k: Spec.Agile.Cipher.key a -> iv: Spec.Agile.Cipher.nonce a -> len: Lib.IntTypes.size_nat -> b: Lib.ByteSequence.bytes{Lib.Sequence.length b = len}
Prims.Tot
[ "total" ]
[]
[ "Spec.Agile.Cipher.cipher_alg", "Spec.Agile.Cipher.key", "Spec.Agile.Cipher.nonce", "Lib.IntTypes.size_nat", "Lib.Sequence.seq", "Lib.IntTypes.uint_t", "Lib.IntTypes.U8", "Lib.IntTypes.SEC", "Prims.eq2", "Prims.int", "Lib.Sequence.length", "FStar.Mul.op_Star", "Spec.Agile.Cipher.block_length", "FStar.Seq.Base.slice", "Lib.ByteSequence.bytes", "Prims.b2t", "Prims.op_Equality", "Prims.nat", "FStar.Pervasives.Native.tuple2", "Prims.unit", "Lib.IntTypes.int_t", "Prims.op_Multiply", "Lib.Sequence.generate_blocks", "Lib.IntTypes.max_size_t", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "FStar.Pervasives.Native.Mktuple2", "Spec.Agile.Cipher.ctr_block", "Prims.op_Addition", "Prims.op_GreaterThanOrEqual", "Prims.op_Modulus", "Prims.op_Division", "Prims.bool" ]
[]
false
false
false
false
false
let ctr_stream (a: cipher_alg) (k: key a) (iv: nonce a) (len: size_nat) : b: bytes{length b = len} =
let n_blocks:n: nat{n * block_length a >= len} = if len % block_length a = 0 then len / block_length a else len / block_length a + 1 in let (), blocks = generate_blocks (block_length a) max_size_t n_blocks (fun _ -> unit) (fun i _ -> (), ctr_block a k iv i) () in Seq.slice blocks 0 len
false
FStar.Tactics.Simplifier.fst
FStar.Tactics.Simplifier.step
val step: Prims.unit -> Tac unit
val step: Prims.unit -> Tac unit
let step () : Tac unit = apply_lemma (`lem_iff_trans)
{ "file_name": "ulib/FStar.Tactics.Simplifier.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 32, "end_line": 38, "start_col": 0, "start_line": 37 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.Simplifier open FStar.Tactics.V2 open FStar.Reflection.V2.Formula open FStar.Reflection.Const (* A correct-by-construction logical simplifier * * No calling `norm [simpl]`, that's cheating! *) val lem_iff_refl : #a:Type -> Lemma (a <==> a) let lem_iff_refl #a = () val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c) -> Lemma (a <==> c) let lem_iff_trans #a #b #c _ _ = () let tiff () : Tac unit = apply_lemma (`lem_iff_refl)
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.Const.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.Simplifier.fst" }
[ { "abbrev": false, "full_module": "FStar.Reflection.Const", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.apply_lemma" ]
[]
false
true
false
false
false
let step () : Tac unit =
apply_lemma (`lem_iff_trans)
false
EverParse3d.Actions.Base.fst
EverParse3d.Actions.Base.validate_dep_pair_with_refinement_and_action'
val 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
val 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
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
{ "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": 9, "end_line": 532, "start_col": 0, "start_line": 482 }
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
{ "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
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 ar2) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (LowParse.Spec.Combinators.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.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.Kinds.weak_kind", "EverParse3d.Prelude.refine", "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", "EverParse3d.Actions.Base.validate_drop", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Prims.op_Negation", "EverParse3d.ErrorCode.check_constraint_ok", "Prims._assert", "Prims.eq2", "FStar.Seq.Base.seq", "FStar.UInt8.t", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Combinators.parse_filter_eq", "LowParse.Spec.Combinators.parse_dtuple2_eq'", "LowParse.Spec.Combinators.parse_filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "Prims.op_BarBar", "EverParse3d.Kinds.and_then_kind", "Prims.dtuple2", "EverParse3d.Prelude.parse_dep_pair", "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' (name1: string) (#nz1: _) (#k1: parser_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 res else (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 (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 else 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))
false
FStar.Tactics.Simplifier.fst
FStar.Tactics.Simplifier.tiff
val tiff: Prims.unit -> Tac unit
val tiff: Prims.unit -> Tac unit
let tiff () : Tac unit = apply_lemma (`lem_iff_refl)
{ "file_name": "ulib/FStar.Tactics.Simplifier.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 31, "end_line": 35, "start_col": 0, "start_line": 34 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.Simplifier open FStar.Tactics.V2 open FStar.Reflection.V2.Formula open FStar.Reflection.Const (* A correct-by-construction logical simplifier * * No calling `norm [simpl]`, that's cheating! *) val lem_iff_refl : #a:Type -> Lemma (a <==> a) let lem_iff_refl #a = () val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c) -> Lemma (a <==> c) let lem_iff_trans #a #b #c _ _ = ()
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.Const.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.Simplifier.fst" }
[ { "abbrev": false, "full_module": "FStar.Reflection.Const", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
_: Prims.unit -> FStar.Tactics.Effect.Tac Prims.unit
FStar.Tactics.Effect.Tac
[]
[]
[ "Prims.unit", "FStar.Tactics.V2.Derived.apply_lemma" ]
[]
false
true
false
false
false
let tiff () : Tac unit =
apply_lemma (`lem_iff_refl)
false
FStar.Tactics.Simplifier.fst
FStar.Tactics.Simplifier.is_true
val is_true : term -> Tac bool
val is_true : term -> Tac bool
let is_true t = begin match term_as_formula' t with | True_ -> true | _ -> begin match inspect t with | Tv_App l r -> begin match inspect l with | Tv_Abs b t -> begin match term_as_formula' t with | True_ -> true | _ -> false end | _ -> false end | _ -> false end end
{ "file_name": "ulib/FStar.Tactics.Simplifier.fst", "git_rev": "10183ea187da8e8c426b799df6c825e24c0767d3", "git_url": "https://github.com/FStarLang/FStar.git", "project_name": "FStar" }
{ "end_col": 7, "end_line": 173, "start_col": 0, "start_line": 158 }
(* Copyright 2008-2018 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module FStar.Tactics.Simplifier open FStar.Tactics.V2 open FStar.Reflection.V2.Formula open FStar.Reflection.Const (* A correct-by-construction logical simplifier * * No calling `norm [simpl]`, that's cheating! *) val lem_iff_refl : #a:Type -> Lemma (a <==> a) let lem_iff_refl #a = () val lem_iff_trans : #a:Type -> #b:Type -> #c:Type -> squash (a <==> b) -> squash (b <==> c) -> Lemma (a <==> c) let lem_iff_trans #a #b #c _ _ = () let tiff () : Tac unit = apply_lemma (`lem_iff_refl) let step () : Tac unit = apply_lemma (`lem_iff_trans) val lem_true_and_p : #p:Type -> Lemma ((True /\ p) <==> p) let lem_true_and_p #p = () val lem_p_and_true : #p:Type -> Lemma ((p /\ True) <==> p) let lem_p_and_true #p = () val lem_false_and_p : #p:Type -> Lemma ((False /\ p) <==> False) let lem_false_and_p #p = () val lem_p_and_false : #p:Type -> Lemma ((p /\ False) <==> False) let lem_p_and_false #p = () val lem_true_or_p : #p:Type -> Lemma ((True \/ p) <==> True) let lem_true_or_p #p = () val lem_p_or_true : #p:Type -> Lemma ((p \/ True) <==> True) let lem_p_or_true #p = () val lem_false_or_p : #p:Type -> Lemma ((False \/ p) <==> p) let lem_false_or_p #p = () val lem_p_or_false : #p:Type -> Lemma ((p \/ False) <==> p) let lem_p_or_false #p = () val lem_true_imp_p : #p:Type -> Lemma ((True ==> p) <==> p) let lem_true_imp_p #p = () val lem_p_imp_true : #p:Type -> Lemma ((p ==> True) <==> True) let lem_p_imp_true #p = () val lem_false_imp_p : #p:Type -> Lemma ((False ==> p) <==> True) let lem_false_imp_p #p = () val lem_fa_true : #a:Type -> Lemma ((forall (x:a). True) <==> True) let lem_fa_true #a = () val lem_fa_false : #a:Type -> (x:a) -> Lemma ((forall (x:a). False) <==> False) let lem_fa_false #a x = () val lem_ex_false : #a:Type -> Lemma ((exists (x:a). False) <==> False) let lem_ex_false #a = () val lem_ex_true : #a:Type -> (x:a) -> Lemma ((exists (x:a). True) <==> True) let lem_ex_true #a x = () val lem_neg_false : unit -> Lemma (~False <==> True) let lem_neg_false () = () val lem_neg_true : unit -> Lemma (~True <==> False) let lem_neg_true () = () val lem_true_iff_p : #p:Type -> Lemma ((True <==> p) <==> p) let lem_true_iff_p #p = () val lem_false_iff_p : #p:Type -> Lemma ((False <==> p) <==> ~p) let lem_false_iff_p #p = () val lem_p_iff_true : #p:Type -> Lemma ((p <==> True) <==> p) let lem_p_iff_true #p = () val lem_p_iff_false : #p:Type -> Lemma ((p <==> False) <==> ~p) let lem_p_iff_false #p = () val and_cong (#p #q #p' #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p /\ q) <==> (p' /\ q')) let and_cong #p #q #p' #q' _ _ = () val or_cong (#p #q #p' #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p \/ q) <==> (p' \/ q')) let or_cong #p #q #p' #q' _ _ = () val imp_cong (#p #q #p' #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p ==> q) <==> (p' ==> q')) let imp_cong #p #q #p' #q' _ _ = () val fa_cong (#a : Type) (#p #q : a -> Type) : (x:a -> squash (p x <==> q x)) -> Lemma ((forall (x:a). p x) <==> (forall (x:a). q x)) let fa_cong #a #p #q f = assert ((forall (x:a). p x) <==> (forall (x:a). q x)) by ( split(); let do1 () : Tac unit = let _ = l_intros () in let t = quote f in let x = nth_var (-1) in let bb = pose (mk_e_app t [binding_to_term x]) in () in iseq [do1; do1] ) val ex_cong (#a : Type) (#p #q : a -> Type) : (x:a -> squash (p x <==> q x)) -> Lemma ((exists (x:a). p x) <==> (exists (x:a). q x)) let ex_cong #a #p #q f = assert ((exists (x:a). p x) <==> (exists (x:a). q x)) by (assume_safe (fun () -> split(); let do1 () : Tac unit = let [ex] = l_intros () in let (b, pf) = elim_exists (binding_to_term ex) in let t = quote f in let bb = pose (mk_e_app t [binding_to_term b]) in () in iseq [do1; do1] )) val neg_cong (#p #q:Type) : squash (p <==> q) -> Lemma (~p <==> ~q) let neg_cong #p #q _ = () val iff_cong (#p #p' #q #q' : Type) : squash (p <==> p') -> squash (q <==> q') -> Lemma ((p <==> q) <==> (p' <==> q')) let iff_cong #p #p' #q #q' _ _ = () // Absolutely hideous, do something about normalization
{ "checked_file": "/", "dependencies": [ "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Tactics.Effect.fsti.checked", "FStar.Reflection.V2.Formula.fst.checked", "FStar.Reflection.Const.fst.checked", "FStar.Pervasives.fsti.checked" ], "interface_file": false, "source_file": "FStar.Tactics.Simplifier.fst" }
[ { "abbrev": false, "full_module": "FStar.Reflection.Const", "short_module": null }, { "abbrev": false, "full_module": "FStar.Reflection.V2.Formula", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics.V2", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Tactics", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
false
t: FStar.Tactics.NamedView.term -> FStar.Tactics.Effect.Tac Prims.bool
FStar.Tactics.Effect.Tac
[]
[]
[ "FStar.Tactics.NamedView.term", "Prims.bool", "FStar.Reflection.V2.Formula.formula", "FStar.Stubs.Reflection.V2.Data.argv", "FStar.Tactics.NamedView.binder", "FStar.Reflection.V2.Formula.term_as_formula'", "FStar.Tactics.NamedView.named_term_view", "FStar.Tactics.NamedView.inspect" ]
[]
false
true
false
false
false
let is_true t =
match term_as_formula' t with | True_ -> true | _ -> match inspect t with | Tv_App l r -> (match inspect l with | Tv_Abs b t -> (match term_as_formula' t with | True_ -> true | _ -> false) | _ -> false) | _ -> false
false