effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
Prims.Tot
val 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})
[ { "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 } ]
false
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 }
val 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}) 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}) =
false
null
false
{ chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 }
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[ "total" ]
[ "Steel.Channel.Simplex.sprot", "Steel.Channel.Protocol.msg_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.in_state_prop", "Steel.Channel.Simplex.Mkchan_val", "Steel.Channel.Simplex.step", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg", "Prims.op_Addition", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_ctr", "Prims.l_and", "Steel.Channel.Simplex.chan_inv_step_p" ]
[]
(* 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})
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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})
[]
Steel.Channel.Simplex.next_chan_val
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
x: Steel.Channel.Protocol.msg_t p -> vs0: Steel.Channel.Simplex.chan_val{Steel.Channel.Simplex.in_state_prop p vs0} -> vs: Steel.Channel.Simplex.chan_val { Steel.Channel.Simplex.in_state_prop (Steel.Channel.Simplex.step p x) vs /\ Steel.Channel.Simplex.chan_inv_step_p vs0 vs }
{ "end_col": 33, "end_line": 139, "start_col": 6, "start_line": 137 }
Prims.Tot
[ { "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 } ]
false
let step (s:sprot) (x:msg_t s) = step s x
let step (s: sprot) (x: msg_t s) =
false
null
false
step s x
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[ "total" ]
[ "Steel.Channel.Simplex.sprot", "Steel.Channel.Protocol.msg_t", "Steel.Channel.Protocol.step", "Prims.unit", "Steel.Channel.Protocol.protocol" ]
[]
(* 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
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val step : s: Steel.Channel.Simplex.sprot -> x: Steel.Channel.Protocol.msg_t s -> Steel.Channel.Protocol.protocol Prims.unit
[]
Steel.Channel.Simplex.step
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
s: Steel.Channel.Simplex.sprot -> x: Steel.Channel.Protocol.msg_t s -> Steel.Channel.Protocol.protocol Prims.unit
{ "end_col": 41, "end_line": 49, "start_col": 33, "start_line": 49 }
Prims.Tot
val initial_trace (p: prot) : (q: partial_trace_of p {until q == p})
[ { "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 } ]
false
let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p}
val initial_trace (p: prot) : (q: partial_trace_of p {until q == p}) let initial_trace (p: prot) : (q: partial_trace_of p {until q == p}) =
false
null
false
{ to = p; tr = Waiting p }
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[ "total" ]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Protocol.Mkpartial_trace_of", "Steel.Channel.Protocol.Waiting", "Steel.Channel.Protocol.partial_trace_of", "Prims.eq2", "Steel.Channel.Protocol.protocol", "Prims.unit", "Steel.Channel.Protocol.until" ]
[]
(* 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}
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val initial_trace (p: prot) : (q: partial_trace_of p {until q == p})
[]
Steel.Channel.Simplex.initial_trace
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Steel.Channel.Simplex.prot -> q: Steel.Channel.Protocol.partial_trace_of p {Steel.Channel.Protocol.until q == p}
{ "end_col": 26, "end_line": 169, "start_col": 6, "start_line": 169 }
Prims.Tot
val chan_inv_cond (vsend vrecv: chan_val) : vprop
[ { "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 } ]
false
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
val chan_inv_cond (vsend vrecv: chan_val) : vprop let chan_inv_cond (vsend vrecv: chan_val) : vprop =
false
null
false
if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[ "total" ]
[ "Steel.Channel.Simplex.chan_val", "Prims.op_Equality", "Prims.nat", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_ctr", "Steel.Effect.Common.pure", "Prims.eq2", "Prims.bool", "Steel.Channel.Simplex.chan_inv_step", "Steel.Effect.Common.vprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.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)
false
true
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val chan_inv_cond (vsend vrecv: chan_val) : vprop
[]
Steel.Channel.Simplex.chan_inv_cond
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
vsend: Steel.Channel.Simplex.chan_val -> vrecv: Steel.Channel.Simplex.chan_val -> Steel.Effect.Common.vprop
{ "end_col": 34, "end_line": 61, "start_col": 4, "start_line": 59 }
Prims.Tot
val next_trace: #p: _ -> vr: chan_val -> vs: chan_val -> tr: partial_trace_of p -> s: squash (until tr == step vr.chan_prot vr.chan_msg) -> squash (chan_inv_step_p vr vs) -> (ts: partial_trace_of p {until ts == step vs.chan_prot vs.chan_msg})
[ { "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 } ]
false
let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg
val next_trace: #p: _ -> vr: chan_val -> vs: chan_val -> tr: partial_trace_of p -> s: squash (until tr == step vr.chan_prot vr.chan_msg) -> squash (chan_inv_step_p vr vs) -> (ts: partial_trace_of p {until ts == step vs.chan_prot vs.chan_msg}) let next_trace #p (vr: chan_val) (vs: chan_val) (tr: partial_trace_of p) (s: squash (until tr == step vr.chan_prot vr.chan_msg)) (_: squash (chan_inv_step_p vr vs)) : (ts: partial_trace_of p {until ts == step vs.chan_prot vs.chan_msg}) =
false
null
false
let msg:next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[ "total" ]
[ "Steel.Channel.Protocol.protocol", "Prims.unit", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Protocol.partial_trace_of", "Prims.squash", "Prims.eq2", "Steel.Channel.Protocol.until", "Steel.Channel.Simplex.step", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Channel.Protocol.extend_partial_trace", "Prims._assert", "Prims.b2t", "Steel.Channel.Simplex.extensible", "Steel.Channel.Simplex.next_msg_t" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs))
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val next_trace: #p: _ -> vr: chan_val -> vs: chan_val -> tr: partial_trace_of p -> s: squash (until tr == step vr.chan_prot vr.chan_msg) -> squash (chan_inv_step_p vr vs) -> (ts: partial_trace_of p {until ts == step vs.chan_prot vs.chan_msg})
[]
Steel.Channel.Simplex.next_trace
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
vr: Steel.Channel.Simplex.chan_val -> vs: Steel.Channel.Simplex.chan_val -> tr: Steel.Channel.Protocol.partial_trace_of p -> s: Prims.squash (Steel.Channel.Protocol.until tr == Steel.Channel.Simplex.step (Mkchan_val?.chan_prot vr) (Mkchan_val?.chan_msg vr)) -> _: Prims.squash (Steel.Channel.Simplex.chan_inv_step_p vr vs) -> ts: Steel.Channel.Protocol.partial_trace_of p { Steel.Channel.Protocol.until ts == Steel.Channel.Simplex.step (Mkchan_val?.chan_prot vs) (Mkchan_val?.chan_msg vs) }
{ "end_col": 32, "end_line": 305, "start_col": 4, "start_line": 303 }
Steel.Effect.Steel
val recall_trace_ref (#q: _) (r: trace_ref q) (tr tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr')
[ { "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 } ]
false
let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok
val recall_trace_ref (#q: _) (r: trace_ref q) (tr tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') let recall_trace_ref #q (r: trace_ref q) (tr: partial_trace_of q) (tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') =
true
null
false
MRef.recall (history_p tr) r tr' tok
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.trace_ref", "Steel.Channel.Protocol.partial_trace_of", "Steel.MonotonicHigherReference.witnessed", "Steel.Channel.Protocol.extended_to", "Steel.Channel.Simplex.history_p", "Steel.MonotonicHigherReference.recall", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.FractionalPermission.full_perm", "Steel.MonotonicHigherReference.ref", "Prims.unit", "Steel.MonotonicHigherReference.pts_to", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t) let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recall_trace_ref (#q: _) (r: trace_ref q) (tr tr': partial_trace_of q) (tok: MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr')
[]
Steel.Channel.Simplex.recall_trace_ref
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.Channel.Simplex.trace_ref q -> tr: Steel.Channel.Protocol.partial_trace_of q -> tr': Steel.Channel.Protocol.partial_trace_of q -> tok: Steel.MonotonicHigherReference.witnessed r (Steel.Channel.Simplex.history_p tr) -> Steel.Effect.Steel Prims.unit
{ "end_col": 40, "end_line": 427, "start_col": 4, "start_line": 427 }
Steel.Effect.SteelT
val intro_chan_inv (#p: _) (c: chan_t p) (v: chan_val) : SteelT unit (((pts_to c.send half v) `star` (pts_to c.recv half v)) `star` (trace_until c.trace v)) (fun _ -> chan_inv c)
[ { "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 } ]
false
let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v
val intro_chan_inv (#p: _) (c: chan_t p) (v: chan_val) : SteelT unit (((pts_to c.send half v) `star` (pts_to c.recv half v)) `star` (trace_until c.trace v)) (fun _ -> chan_inv c) let intro_chan_inv #p (c: chan_t p) (v: chan_val) : SteelT unit (((pts_to c.send half v) `star` (pts_to c.recv half v)) `star` (trace_until c.trace v)) (fun _ -> chan_inv c) =
true
null
false
intro_chan_inv_eqT c v v
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.intro_chan_inv_eqT", "Prims.unit", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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)
[]
Steel.Channel.Simplex.intro_chan_inv
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan_t p -> v: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
{ "end_col": 28, "end_line": 157, "start_col": 4, "start_line": 157 }
Steel.Effect.Steel
val next_trace_st (#p: _) (vr vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg)
[ { "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 } ]
false
let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts
val next_trace_st (#p: _) (vr vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) let next_trace_st #p (vr: chan_val) (vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) =
true
null
false
elim_pure (chan_inv_step_p vr vs); let ts:extension_of tr = next_trace vr vs tr () () in return ts
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Protocol.protocol", "Prims.unit", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Protocol.partial_trace_of", "Steel.Effect.Atomic.return", "Steel.Channel.Protocol.extension_of", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "FStar.Algebra.CommMonoid.Equiv.__proj__CM__item__unit", "Steel.Effect.Common.vprop", "Steel.Effect.Common.req", "Steel.Effect.Common.rm", "Steel.Channel.Simplex.next_trace", "Steel.Effect.Atomic.elim_pure", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Channel.Simplex.chan_inv_step", "Steel.Effect.Common.emp", "Steel.Effect.Common.rmem", "Prims.eq2", "Steel.Channel.Protocol.until", "Steel.Channel.Simplex.step", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val next_trace_st (#p: _) (vr vs: chan_val) (tr: partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg)
[]
Steel.Channel.Simplex.next_trace_st
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
vr: Steel.Channel.Simplex.chan_val -> vs: Steel.Channel.Simplex.chan_val -> tr: Steel.Channel.Protocol.partial_trace_of p -> Steel.Effect.Steel (Steel.Channel.Protocol.extension_of tr)
{ "end_col": 13, "end_line": 315, "start_col": 4, "start_line": 313 }
Steel.Effect.Steel
val intro_chan_inv_cond_eqT (vs vr: chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True)
[ { "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 } ]
false
let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
val intro_chan_inv_cond_eqT (vs vr: chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) let intro_chan_inv_cond_eqT (vs vr: chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) =
true
null
false
intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ())
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.chan_val", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Memory.mem", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Prims.eq2", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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)
[]
Steel.Channel.Simplex.intro_chan_inv_cond_eqT
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.Steel Prims.unit
{ "end_col": 76, "end_line": 86, "start_col": 4, "start_line": 85 }
Steel.Effect.SteelT
val intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr)
[ { "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 } ]
false
let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
val intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) let intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) =
true
null
false
Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ())
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.chan_val", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.chan_inv_step", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Memory.mem", "Prims.unit", "Steel.Utils.extract_pure", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Effect.Common.vprop" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val intro_chan_inv_cond_stepT (vs vr: chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr)
[]
Steel.Channel.Simplex.intro_chan_inv_cond_stepT
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
{ "end_col": 76, "end_line": 92, "start_col": 4, "start_line": 91 }
Steel.Effect.SteelT
val intro_in_state (r: ref chan_val) (p: prot) (v: chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p)
[ { "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 } ]
false
let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v)
val intro_in_state (r: ref chan_val) (p: prot) (v: chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) let intro_in_state (r: ref chan_val) (p: prot) (v: chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) =
true
null
false
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))
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.HigherReference.ref", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_val_p", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.in_state_slprop", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Steel.Channel.Simplex.in_state_prop", "Steel.Channel.Simplex.in_state" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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)
[]
Steel.Channel.Simplex.intro_in_state
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.HigherReference.ref Steel.Channel.Simplex.chan_val -> p: Steel.Channel.Simplex.prot -> v: Steel.Channel.Simplex.chan_val_p p -> Steel.Effect.SteelT Prims.unit
{ "end_col": 83, "end_line": 163, "start_col": 4, "start_line": 162 }
Steel.Effect.Steel
val intro_chan_inv_eqT (#p: _) (c: chan_t p) (vs vr: chan_val) : Steel unit (((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True)
[ { "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 } ]
false
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
val intro_chan_inv_eqT (#p: _) (c: chan_t p) (vs vr: chan_val) : Steel unit (((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) let intro_chan_inv_eqT #p (c: chan_t p) (vs: chan_val) (vr: chan_val) : Steel unit (((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) =
true
null
false
intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.intro_chan_inv_auxT", "Prims.unit", "Steel.Channel.Simplex.intro_chan_inv_cond_eqT", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.eq2", "Prims.l_True" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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)
[]
Steel.Channel.Simplex.intro_chan_inv_eqT
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan_t p -> vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.Steel Prims.unit
{ "end_col": 25, "end_line": 122, "start_col": 4, "start_line": 121 }
Steel.Effect.SteelT
val intro_chan_inv_stepT (#p: _) (c: chan_t p) (vs vr: chan_val) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_step vr vs)) (fun _ -> chan_inv c)
[ { "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 } ]
false
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
val intro_chan_inv_stepT (#p: _) (c: chan_t p) (vs vr: chan_val) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_step vr vs)) (fun _ -> chan_inv c) let intro_chan_inv_stepT #p (c: chan_t p) (vs: chan_val) (vr: chan_val) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_step vr vs)) (fun _ -> chan_inv c) =
true
null
false
intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.intro_chan_inv_auxT", "Prims.unit", "Steel.Channel.Simplex.intro_chan_inv_cond_stepT", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv_step", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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)
[]
Steel.Channel.Simplex.intro_chan_inv_stepT
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan_t p -> vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
{ "end_col": 25, "end_line": 112, "start_col": 4, "start_line": 111 }
Steel.Effect.SteelT
val intro_chan_inv_auxT (#p: _) (#vs #vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c)
[ { "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 } ]
false
let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs)
val intro_chan_inv_auxT (#p: _) (#vs #vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c) let intro_chan_inv_auxT #p (#vs: chan_val) (#vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c) =
true
null
false
intro_exists _ (fun (vr: chan_val) -> ((pts_to c.recv half vr) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)); intro_exists _ (fun (vs: chan_val) -> (pts_to c.send half vs) `star` (chan_inv_recv c vs))
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.chan_t", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.chan_inv_recv", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Channel.Simplex.chan_inv" ]
[]
(* 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)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val intro_chan_inv_auxT (#p: _) (#vs #vr: chan_val) (c: chan_t p) : SteelT unit ((((pts_to c.send half vs) `star` (pts_to c.recv half vr)) `star` (trace_until c.trace vr)) `star` (chan_inv_cond vs vr)) (fun _ -> chan_inv c)
[]
Steel.Channel.Simplex.intro_chan_inv_auxT
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan_t p -> Steel.Effect.SteelT Prims.unit
{ "end_col": 89, "end_line": 103, "start_col": 4, "start_line": 102 }
Steel.Effect.Steel
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)
[ { "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 } ]
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))); ()
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) =
true
null
false
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)))); ()
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "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" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val 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)
[]
Steel.Channel.Simplex.intro_trace_until
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
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
{ "end_col": 6, "end_line": 181, "start_col": 4, "start_line": 176 }
Steel.Effect.SteelT
val intro_trace_until_init (#p: _) (c: chan_t p) (v: init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v)
[ { "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 } ]
false
let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v)
val intro_trace_until_init (#p: _) (c: chan_t p) (v: init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) let intro_trace_until_init #p (c: chan_t p) (v: init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) =
true
null
false
intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); rewrite_slprop ((MRef.pts_to c.trace full_perm (initial_trace p)) `star` (pure (until (initial_trace p) == step v.chan_prot v.chan_msg))) ((MRef.pts_to c.trace full_perm (initial_trace p)) `star` (pure (until (initial_trace p) == step v.chan_prot v.chan_msg))) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v)
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.init_chan_val", "Steel.Effect.Atomic.intro_exists", "Steel.Channel.Protocol.partial_trace_of", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.initial_trace", "Steel.Channel.Simplex.trace_until_prop", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "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.Memory.mem", "Steel.Effect.Atomic.intro_pure", "Steel.Channel.Simplex.trace_until", "Steel.Effect.Common.vprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p))
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val intro_trace_until_init (#p: _) (c: chan_t p) (v: init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v)
[]
Steel.Channel.Simplex.intro_trace_until_init
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan_t p -> v: Steel.Channel.Simplex.init_chan_val p -> Steel.Effect.SteelT Prims.unit
{ "end_col": 63, "end_line": 195, "start_col": 4, "start_line": 188 }
Steel.Effect.SteelT
val gather_r (#p: sprot) (r: ref chan_val) (v: chan_val) : SteelT unit ((pts_to r half v) `star` (in_state r p)) (fun _ -> (pts_to r full_perm v) `star` (in_state_slprop p v))
[ { "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 } ]
false
let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ())
val gather_r (#p: sprot) (r: ref chan_val) (v: chan_val) : SteelT unit ((pts_to r half v) `star` (in_state r p)) (fun _ -> (pts_to r full_perm v) `star` (in_state_slprop p v)) let gather_r (#p: sprot) (r: ref chan_val) (v: chan_val) : SteelT unit ((pts_to r half v) `star` (in_state r p)) (fun _ -> (pts_to r full_perm v) `star` (in_state_slprop p v)) =
true
null
false
let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ())
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.sprot", "Steel.HigherReference.ref", "Steel.Channel.Simplex.chan_val", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.in_state_slprop", "FStar.Ghost.reveal", "Steel.Memory.mem", "Prims.unit", "Steel.HigherReference.pts_to", "Steel.FractionalPermission.sum_perm", "Steel.Channel.Simplex.half", "Steel.FractionalPermission.full_perm", "Steel.HigherReference.gather", "Steel.HigherReference.higher_ref_pts_to_injective_eq", "FStar.Ghost.erased", "Steel.Effect.Atomic.witness_exists", "Steel.Effect.Common.star", "Steel.Effect.Common.vprop", "Steel.Channel.Simplex.in_state" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gather_r (#p: sprot) (r: ref chan_val) (v: chan_val) : SteelT unit ((pts_to r half v) `star` (in_state r p)) (fun _ -> (pts_to r full_perm v) `star` (in_state_slprop p v))
[]
Steel.Channel.Simplex.gather_r
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.HigherReference.ref Steel.Channel.Simplex.chan_val -> v: Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Prims.unit
{ "end_col": 77, "end_line": 281, "start_col": 3, "start_line": 277 }
Steel.Effect.SteelT
val update_channel (#p: sprot) (#q: _) (c: chan_t q) (x: msg_t p) (vs: chan_val) (r: ref chan_val) : SteelT chan_val ((pts_to r full_perm vs) `star` (in_state_slprop p vs)) (fun vs' -> (pts_to r full_perm vs') `star` ((in_state_slprop (step p x) vs') `star` (chan_inv_step vs vs')))
[ { "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 } ]
false
let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs'
val update_channel (#p: sprot) (#q: _) (c: chan_t q) (x: msg_t p) (vs: chan_val) (r: ref chan_val) : SteelT chan_val ((pts_to r full_perm vs) `star` (in_state_slprop p vs)) (fun vs' -> (pts_to r full_perm vs') `star` ((in_state_slprop (step p x) vs') `star` (chan_inv_step vs vs'))) let update_channel (#p: sprot) #q (c: chan_t q) (x: msg_t p) (vs: chan_val) (r: ref chan_val) : SteelT chan_val ((pts_to r full_perm vs) `star` (in_state_slprop p vs)) (fun vs' -> (pts_to r full_perm vs') `star` ((in_state_slprop (step p x) vs') `star` (chan_inv_step vs vs'))) =
true
null
false
elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs'
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.sprot", "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Protocol.msg_t", "Steel.Channel.Simplex.chan_val", "Steel.HigherReference.ref", "Steel.Effect.Atomic.return", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.VStar", "Steel.Channel.Simplex.chan_inv_step", "Steel.Effect.Common.pure", "Steel.Channel.Simplex.in_state_prop", "Steel.Channel.Simplex.step", "Steel.HigherReference.pts_to", "Steel.FractionalPermission.full_perm", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Effect.Atomic.intro_pure", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.HigherReference.write", "Prims.l_and", "Steel.Channel.Simplex.next_chan_val", "Steel.Effect.Atomic.elim_pure", "Steel.Effect.Common.star", "Steel.Channel.Simplex.in_state_slprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_channel (#p: sprot) (#q: _) (c: chan_t q) (x: msg_t p) (vs: chan_val) (r: ref chan_val) : SteelT chan_val ((pts_to r full_perm vs) `star` (in_state_slprop p vs)) (fun vs' -> (pts_to r full_perm vs') `star` ((in_state_slprop (step p x) vs') `star` (chan_inv_step vs vs')))
[]
Steel.Channel.Simplex.update_channel
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan_t q -> x: Steel.Channel.Protocol.msg_t p -> vs: Steel.Channel.Simplex.chan_val -> r: Steel.HigherReference.ref Steel.Channel.Simplex.chan_val -> Steel.Effect.SteelT Steel.Channel.Simplex.chan_val
{ "end_col": 14, "end_line": 268, "start_col": 4, "start_line": 263 }
Steel.Effect.SteelT
val trace (#q:prot) (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr) emp (fun _ -> emp)
[ { "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.Atomic", "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 } ]
false
let trace #q (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr) emp (fun _ -> emp) = let _ = send_receive_prelude cc in let tr = witness_trace_until cc.chan_chan.trace in intro_chan_inv_auxT cc.chan_chan; Steel.SpinLock.release cc.chan_lock; tr
val trace (#q:prot) (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr) emp (fun _ -> emp) let trace #q (cc: chan q) : SteelT (tr: partial_trace_of q & history cc tr) emp (fun _ -> emp) =
true
null
false
let _ = send_receive_prelude cc in let tr = witness_trace_until cc.chan_chan.trace in intro_chan_inv_auxT cc.chan_chan; Steel.SpinLock.release cc.chan_lock; tr
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan", "Prims.dtuple2", "Steel.Channel.Protocol.partial_trace_of", "Steel.Channel.Simplex.history", "Prims.unit", "Steel.SpinLock.release", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.intro_chan_inv_auxT", "Steel.Channel.Simplex.chan_val", "Steel.MonotonicHigherReference.witnessed", "Steel.Channel.Protocol.extended_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.history_p", "Steel.Channel.Simplex.witness_trace_until", "FStar.Pervasives.Native.tuple2", "Steel.Channel.Simplex.send_receive_prelude", "Steel.Effect.Common.emp", "Steel.Effect.Common.vprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t) let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok let prot_equals #q (#p:_) (#vr:chan_val) (cc:chan q) : Steel unit (pts_to cc.chan_chan.recv half vr `star` receiver cc p) (fun _ -> pts_to cc.chan_chan.recv half vr `star` receiver cc p) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) = let vr' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #vr #_ cc.chan_chan.recv; rewrite_slprop (in_state_slprop _ _) (in_state_slprop p vr) (fun _ -> ()); elim_pure _; intro_in_state _ _ vr let witness_trace_until #q (#vr:chan_val) (r:trace_ref q) : SteelT (tr:partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr) = let tr = MRef.read_refine r in let tok = MRef.witness r (history_p tr) tr () in elim_pure (until tr == step vr.chan_prot vr.chan_msg); intro_trace_until r tr vr; (| tr, tok |) let trace #q (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val trace (#q:prot) (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr) emp (fun _ -> emp)
[]
Steel.Channel.Simplex.trace
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
cc: Steel.Channel.Simplex.chan q -> Steel.Effect.SteelT (Prims.dtuple2 (Steel.Channel.Protocol.partial_trace_of q) (fun tr -> Steel.Channel.Simplex.history cc tr))
{ "end_col": 6, "end_line": 458, "start_col": 3, "start_line": 454 }
Steel.Effect.SteelT
val witness_trace_until (#q: _) (#vr: chan_val) (r: trace_ref q) : SteelT (tr: partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr)
[ { "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 } ]
false
let witness_trace_until #q (#vr:chan_val) (r:trace_ref q) : SteelT (tr:partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr) = let tr = MRef.read_refine r in let tok = MRef.witness r (history_p tr) tr () in elim_pure (until tr == step vr.chan_prot vr.chan_msg); intro_trace_until r tr vr; (| tr, tok |)
val witness_trace_until (#q: _) (#vr: chan_val) (r: trace_ref q) : SteelT (tr: partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr) let witness_trace_until #q (#vr: chan_val) (r: trace_ref q) : SteelT (tr: partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr) =
true
null
false
let tr = MRef.read_refine r in let tok = MRef.witness r (history_p tr) tr () in elim_pure (until tr == step vr.chan_prot vr.chan_msg); intro_trace_until r tr vr; (| tr, tok |)
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.trace_ref", "Prims.Mkdtuple2", "Steel.Channel.Protocol.partial_trace_of", "Steel.MonotonicHigherReference.witnessed", "Steel.Channel.Protocol.extended_to", "Steel.Channel.Simplex.history_p", "Prims.dtuple2", "Prims.unit", "Steel.Channel.Simplex.intro_trace_until", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "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", "FStar.Ghost.reveal", "Steel.MonotonicHigherReference.ref", "Steel.MonotonicHigherReference.witness", "Steel.FractionalPermission.full_perm", "Steel.MonotonicHigherReference.read_refine", "Steel.Effect.Common.pure", "Steel.Effect.Common.vprop", "Steel.Channel.Simplex.trace_until" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t) let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok let prot_equals #q (#p:_) (#vr:chan_val) (cc:chan q) : Steel unit (pts_to cc.chan_chan.recv half vr `star` receiver cc p) (fun _ -> pts_to cc.chan_chan.recv half vr `star` receiver cc p) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) = let vr' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #vr #_ cc.chan_chan.recv; rewrite_slprop (in_state_slprop _ _) (in_state_slprop p vr) (fun _ -> ()); elim_pure _; intro_in_state _ _ vr let witness_trace_until #q (#vr:chan_val) (r:trace_ref q) : SteelT (tr:partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val witness_trace_until (#q: _) (#vr: chan_val) (r: trace_ref q) : SteelT (tr: partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr)
[]
Steel.Channel.Simplex.witness_trace_until
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.Channel.Simplex.trace_ref q -> Steel.Effect.SteelT (Prims.dtuple2 (Steel.Channel.Protocol.partial_trace_of q) (fun tr -> Steel.MonotonicHigherReference.witnessed r (Steel.Channel.Simplex.history_p tr)))
{ "end_col": 17, "end_line": 449, "start_col": 3, "start_line": 445 }
Steel.Effect.Steel
val prot_equals (#q #p: _) (#vr: chan_val) (cc: chan q) : Steel unit ((pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (fun _ -> (pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p)
[ { "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 } ]
false
let prot_equals #q (#p:_) (#vr:chan_val) (cc:chan q) : Steel unit (pts_to cc.chan_chan.recv half vr `star` receiver cc p) (fun _ -> pts_to cc.chan_chan.recv half vr `star` receiver cc p) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) = let vr' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #vr #_ cc.chan_chan.recv; rewrite_slprop (in_state_slprop _ _) (in_state_slprop p vr) (fun _ -> ()); elim_pure _; intro_in_state _ _ vr
val prot_equals (#q #p: _) (#vr: chan_val) (cc: chan q) : Steel unit ((pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (fun _ -> (pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) let prot_equals #q (#p: _) (#vr: chan_val) (cc: chan q) : Steel unit ((pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (fun _ -> (pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) =
true
null
false
let vr' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #vr #_ cc.chan_chan.recv; rewrite_slprop (in_state_slprop _ _) (in_state_slprop p vr) (fun _ -> ()); elim_pure _; intro_in_state _ _ vr
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.chan", "Steel.Channel.Simplex.intro_in_state", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Prims.unit", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.in_state_prop", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Channel.Simplex.in_state_slprop", "FStar.Ghost.reveal", "Steel.Memory.mem", "Steel.HigherReference.higher_ref_pts_to_injective_eq", "Steel.Channel.Simplex.half", "FStar.Ghost.erased", "Steel.Effect.Atomic.witness_exists", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Effect.Common.vprop", "Steel.Channel.Simplex.receiver", "Steel.Effect.Common.rmem", "Prims.l_True", "Prims.eq2", "Steel.Channel.Protocol.protocol", "Steel.Channel.Simplex.step", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t) let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok let prot_equals #q (#p:_) (#vr:chan_val) (cc:chan q) : Steel unit (pts_to cc.chan_chan.recv half vr `star` receiver cc p) (fun _ -> pts_to cc.chan_chan.recv half vr `star` receiver cc p) (requires fun _ -> True)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val prot_equals (#q #p: _) (#vr: chan_val) (cc: chan q) : Steel unit ((pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (fun _ -> (pts_to cc.chan_chan.recv half vr) `star` (receiver cc p)) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p)
[]
Steel.Channel.Simplex.prot_equals
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
cc: Steel.Channel.Simplex.chan q -> Steel.Effect.Steel Prims.unit
{ "end_col": 25, "end_line": 439, "start_col": 3, "start_line": 435 }
Steel.Effect.Steel
val extend_trace (#p:prot) (#next:prot) (c:chan p) (previous:partial_trace_of p) (hprevious:history c previous) : Steel (t:extension_of previous & history c t) (receiver c next) (fun t -> receiver c next) (requires fun _ -> True) (ensures fun _ t _ -> until (dfst t) == next)
[ { "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.Atomic", "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 } ]
false
let extend_trace (#q:prot) (#p:prot) (cc:chan q) (tr:partial_trace_of q) (htr:history cc tr) : Steel (tr':extension_of tr & history cc tr') (receiver cc p) (fun t -> receiver cc p) (requires fun _ -> True) (ensures fun _ t _ -> until (dfst t) == p) = let _ = send_receive_prelude cc in let tr' = extend_history cc htr in let _ = prot_equals cc in intro_chan_inv_auxT cc.chan_chan; Steel.SpinLock.release cc.chan_lock; tr'
val extend_trace (#p:prot) (#next:prot) (c:chan p) (previous:partial_trace_of p) (hprevious:history c previous) : Steel (t:extension_of previous & history c t) (receiver c next) (fun t -> receiver c next) (requires fun _ -> True) (ensures fun _ t _ -> until (dfst t) == next) let extend_trace (#q #p: prot) (cc: chan q) (tr: partial_trace_of q) (htr: history cc tr) : Steel (tr': extension_of tr & history cc tr') (receiver cc p) (fun t -> receiver cc p) (requires fun _ -> True) (ensures fun _ t _ -> until (dfst t) == p) =
true
null
false
let _ = send_receive_prelude cc in let tr' = extend_history cc htr in let _ = prot_equals cc in intro_chan_inv_auxT cc.chan_chan; Steel.SpinLock.release cc.chan_lock; tr'
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan", "Steel.Channel.Protocol.partial_trace_of", "Steel.Channel.Simplex.history", "Prims.dtuple2", "Steel.Channel.Protocol.extension_of", "Prims.unit", "Steel.SpinLock.release", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.intro_chan_inv_auxT", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.prot_equals", "Steel.Channel.Simplex.extend_history", "FStar.Pervasives.Native.tuple2", "Steel.Channel.Simplex.send_receive_prelude", "Steel.Channel.Simplex.receiver", "Steel.Effect.Common.vprop", "Steel.Effect.Common.rmem", "Prims.l_True", "Prims.eq2", "Steel.Channel.Protocol.protocol", "Steel.Channel.Protocol.until", "FStar.Pervasives.dfst" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t) let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok let prot_equals #q (#p:_) (#vr:chan_val) (cc:chan q) : Steel unit (pts_to cc.chan_chan.recv half vr `star` receiver cc p) (fun _ -> pts_to cc.chan_chan.recv half vr `star` receiver cc p) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) = let vr' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #vr #_ cc.chan_chan.recv; rewrite_slprop (in_state_slprop _ _) (in_state_slprop p vr) (fun _ -> ()); elim_pure _; intro_in_state _ _ vr let witness_trace_until #q (#vr:chan_val) (r:trace_ref q) : SteelT (tr:partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr) = let tr = MRef.read_refine r in let tok = MRef.witness r (history_p tr) tr () in elim_pure (until tr == step vr.chan_prot vr.chan_msg); intro_trace_until r tr vr; (| tr, tok |) let trace #q (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr) emp (fun _ -> emp) = let _ = send_receive_prelude cc in let tr = witness_trace_until cc.chan_chan.trace in intro_chan_inv_auxT cc.chan_chan; Steel.SpinLock.release cc.chan_lock; tr let extend_history #q (#tr:partial_trace_of q) (#v:chan_val) (c:chan q) (tok:history c tr) : Steel (tr':extension_of tr & history c tr') (pts_to c.chan_chan.recv half v `star` trace_until c.chan_chan.trace v) (fun _ -> pts_to c.chan_chan.recv half v `star` trace_until c.chan_chan.trace v) (requires fun _ -> True) (ensures fun _ tr' _ -> until (dfst tr') == step v.chan_prot v.chan_msg) = let tr' = MRef.read_refine c.chan_chan.trace in let _ = recall_trace_ref c.chan_chan.trace tr tr' tok in let tok' = MRef.witness c.chan_chan.trace (history_p tr') tr' () in elim_pure (until tr' == step v.chan_prot v.chan_msg); intro_trace_until c.chan_chan.trace tr' v; let tr'' : extension_of tr = tr' in (| tr'', tok' |) let extend_trace (#q:prot) (#p:prot) (cc:chan q) (tr:partial_trace_of q) (htr:history cc tr) : Steel (tr':extension_of tr & history cc tr') (receiver cc p) (fun t -> receiver cc p) (requires fun _ -> True)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val extend_trace (#p:prot) (#next:prot) (c:chan p) (previous:partial_trace_of p) (hprevious:history c previous) : Steel (t:extension_of previous & history c t) (receiver c next) (fun t -> receiver c next) (requires fun _ -> True) (ensures fun _ t _ -> until (dfst t) == next)
[]
Steel.Channel.Simplex.extend_trace
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan p -> previous: Steel.Channel.Protocol.partial_trace_of p -> hprevious: Steel.Channel.Simplex.history c previous -> Steel.Effect.Steel (Prims.dtuple2 (Steel.Channel.Protocol.extension_of previous) (fun t -> Steel.Channel.Simplex.history c t))
{ "end_col": 7, "end_line": 493, "start_col": 3, "start_line": 488 }
Steel.Effect.SteelT
val send_receive_prelude (#p: prot) (cc: chan p) : SteelT (chan_val & chan_val) emp (fun v -> (((pts_to cc.chan_chan.send half (fst v)) `star` (pts_to cc.chan_chan.recv half (snd v))) `star` (trace_until cc.chan_chan.trace (snd v))) `star` (chan_inv_cond (fst v) (snd v)))
[ { "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 } ]
false
let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr)
val send_receive_prelude (#p: prot) (cc: chan p) : SteelT (chan_val & chan_val) emp (fun v -> (((pts_to cc.chan_chan.send half (fst v)) `star` (pts_to cc.chan_chan.recv half (snd v))) `star` (trace_until cc.chan_chan.trace (snd v))) `star` (chan_inv_cond (fst v) (snd v))) let send_receive_prelude (#p: prot) (cc: chan p) : SteelT (chan_val & chan_val) emp (fun v -> (((pts_to cc.chan_chan.send half (fst v)) `star` (pts_to cc.chan_chan.recv half (snd v))) `star` (trace_until cc.chan_chan.trace (snd v))) `star` (chan_inv_cond (fst v) (snd v))) =
true
null
false
let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop ((trace_until _ _) `star` (chan_inv_cond _ _)) ((trace_until cc.chan_chan.trace vr) `star` (chan_inv_cond vs vr)) (fun _ -> ()); return (vs, vr)
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan", "Steel.Effect.Atomic.return", "FStar.Pervasives.Native.tuple2", "Steel.Channel.Simplex.chan_val", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.VStar", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Effect.Common.vprop", "FStar.Pervasives.Native.Mktuple2", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Effect.Common.star", "FStar.Ghost.reveal", "Steel.Memory.mem", "Steel.HigherReference.read", "FStar.Ghost.erased", "Steel.Effect.Atomic.witness_exists", "Steel.HigherReference.read_refine", "Steel.Channel.Simplex.chan_inv_recv", "Steel.SpinLock.acquire", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.chan_t", "Steel.Effect.Common.emp", "FStar.Pervasives.Native.fst", "FStar.Pervasives.Native.snd" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star`
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val send_receive_prelude (#p: prot) (cc: chan p) : SteelT (chan_val & chan_val) emp (fun v -> (((pts_to cc.chan_chan.send half (fst v)) `star` (pts_to cc.chan_chan.recv half (snd v))) `star` (trace_until cc.chan_chan.trace (snd v))) `star` (chan_inv_cond (fst v) (snd v)))
[]
Steel.Channel.Simplex.send_receive_prelude
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
cc: Steel.Channel.Simplex.chan p -> Steel.Effect.SteelT (Steel.Channel.Simplex.chan_val * Steel.Channel.Simplex.chan_val)
{ "end_col": 19, "end_line": 369, "start_col": 3, "start_line": 361 }
Steel.Effect.Steel
val extend_history (#q: _) (#tr: partial_trace_of q) (#v: chan_val) (c: chan q) (tok: history c tr) : Steel (tr': extension_of tr & history c tr') ((pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (fun _ -> (pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (requires fun _ -> True) (ensures fun _ tr' _ -> until (dfst tr') == step v.chan_prot v.chan_msg)
[ { "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 } ]
false
let extend_history #q (#tr:partial_trace_of q) (#v:chan_val) (c:chan q) (tok:history c tr) : Steel (tr':extension_of tr & history c tr') (pts_to c.chan_chan.recv half v `star` trace_until c.chan_chan.trace v) (fun _ -> pts_to c.chan_chan.recv half v `star` trace_until c.chan_chan.trace v) (requires fun _ -> True) (ensures fun _ tr' _ -> until (dfst tr') == step v.chan_prot v.chan_msg) = let tr' = MRef.read_refine c.chan_chan.trace in let _ = recall_trace_ref c.chan_chan.trace tr tr' tok in let tok' = MRef.witness c.chan_chan.trace (history_p tr') tr' () in elim_pure (until tr' == step v.chan_prot v.chan_msg); intro_trace_until c.chan_chan.trace tr' v; let tr'' : extension_of tr = tr' in (| tr'', tok' |)
val extend_history (#q: _) (#tr: partial_trace_of q) (#v: chan_val) (c: chan q) (tok: history c tr) : Steel (tr': extension_of tr & history c tr') ((pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (fun _ -> (pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (requires fun _ -> True) (ensures fun _ tr' _ -> until (dfst tr') == step v.chan_prot v.chan_msg) let extend_history #q (#tr: partial_trace_of q) (#v: chan_val) (c: chan q) (tok: history c tr) : Steel (tr': extension_of tr & history c tr') ((pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (fun _ -> (pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (requires fun _ -> True) (ensures fun _ tr' _ -> until (dfst tr') == step v.chan_prot v.chan_msg) =
true
null
false
let tr' = MRef.read_refine c.chan_chan.trace in let _ = recall_trace_ref c.chan_chan.trace tr tr' tok in let tok' = MRef.witness c.chan_chan.trace (history_p tr') tr' () in elim_pure (until tr' == step v.chan_prot v.chan_msg); intro_trace_until c.chan_chan.trace tr' v; let tr'':extension_of tr = tr' in (| tr'', tok' |)
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Protocol.protocol", "Prims.unit", "Steel.Channel.Protocol.partial_trace_of", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.chan", "Steel.Channel.Simplex.history", "Prims.Mkdtuple2", "Steel.Channel.Protocol.extension_of", "Prims.dtuple2", "Steel.Channel.Simplex.intro_trace_until", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.eq2", "Steel.Channel.Protocol.until", "Steel.Channel.Simplex.step", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg", "Steel.MonotonicHigherReference.witnessed", "Steel.Channel.Protocol.extended_to", "FStar.Ghost.reveal", "Steel.MonotonicHigherReference.ref", "Steel.Channel.Simplex.history_p", "Steel.MonotonicHigherReference.witness", "Steel.FractionalPermission.full_perm", "Steel.Channel.Simplex.recall_trace_ref", "Steel.MonotonicHigherReference.read_refine", "Steel.Effect.Common.pure", "Steel.Effect.Common.vprop", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.trace_until", "Steel.Effect.Common.rmem", "Prims.l_True", "FStar.Pervasives.dfst" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () ) let history_p' (#p:prot) (t:partial_trace_of p) (s:partial_trace_of p) : prop = t `extended_to` s /\ True let history_p (#p:prot) (t:partial_trace_of p) : MRef.stable_property extended_to = history_p' t let history (#p:prot) (c:chan p) (t:partial_trace_of p) : Type0 = MRef.witnessed c.chan_chan.trace (history_p t) let recall_trace_ref #q (r:trace_ref q) (tr tr':partial_trace_of q) (tok:MRef.witnessed r (history_p tr)) : Steel unit (MRef.pts_to r full_perm tr') (fun _ -> MRef.pts_to r full_perm tr') (requires fun _ -> True) (ensures fun _ _ _ -> history_p tr tr') = MRef.recall (history_p tr) r tr' tok let prot_equals #q (#p:_) (#vr:chan_val) (cc:chan q) : Steel unit (pts_to cc.chan_chan.recv half vr `star` receiver cc p) (fun _ -> pts_to cc.chan_chan.recv half vr `star` receiver cc p) (requires fun _ -> True) (ensures fun _ _ _ -> step vr.chan_prot vr.chan_msg == p) = let vr' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #vr #_ cc.chan_chan.recv; rewrite_slprop (in_state_slprop _ _) (in_state_slprop p vr) (fun _ -> ()); elim_pure _; intro_in_state _ _ vr let witness_trace_until #q (#vr:chan_val) (r:trace_ref q) : SteelT (tr:partial_trace_of q & MRef.witnessed r (history_p tr)) (trace_until r vr) (fun _ -> trace_until r vr) = let tr = MRef.read_refine r in let tok = MRef.witness r (history_p tr) tr () in elim_pure (until tr == step vr.chan_prot vr.chan_msg); intro_trace_until r tr vr; (| tr, tok |) let trace #q (cc:chan q) : SteelT (tr:partial_trace_of q & history cc tr) emp (fun _ -> emp) = let _ = send_receive_prelude cc in let tr = witness_trace_until cc.chan_chan.trace in intro_chan_inv_auxT cc.chan_chan; Steel.SpinLock.release cc.chan_lock; tr let extend_history #q (#tr:partial_trace_of q) (#v:chan_val) (c:chan q) (tok:history c tr) : Steel (tr':extension_of tr & history c tr') (pts_to c.chan_chan.recv half v `star` trace_until c.chan_chan.trace v) (fun _ -> pts_to c.chan_chan.recv half v `star` trace_until c.chan_chan.trace v) (requires fun _ -> True)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val extend_history (#q: _) (#tr: partial_trace_of q) (#v: chan_val) (c: chan q) (tok: history c tr) : Steel (tr': extension_of tr & history c tr') ((pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (fun _ -> (pts_to c.chan_chan.recv half v) `star` (trace_until c.chan_chan.trace v)) (requires fun _ -> True) (ensures fun _ tr' _ -> until (dfst tr') == step v.chan_prot v.chan_msg)
[]
Steel.Channel.Simplex.extend_history
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan q -> tok: Steel.Channel.Simplex.history c tr -> Steel.Effect.Steel (Prims.dtuple2 (Steel.Channel.Protocol.extension_of tr) (fun tr' -> Steel.Channel.Simplex.history c tr'))
{ "end_col": 20, "end_line": 477, "start_col": 3, "start_line": 471 }
Steel.Effect.Steel
val update_trace (#p: _) (r: trace_ref p) (vr vs: chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True)
[ { "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 } ]
false
let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg))
val update_trace (#p: _) (r: trace_ref p) (vr vs: chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) let update_trace #p (r: trace_ref p) (vr: chan_val) (vs: chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) =
true
null
false
intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts:extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts: partial_trace_of p) -> (MRef.pts_to r full_perm ts) `star` (pure (until ts == step vs.chan_prot vs.chan_msg)))
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.trace_ref", "Steel.Channel.Simplex.chan_val", "Steel.Effect.Atomic.intro_exists", "Steel.Channel.Protocol.partial_trace_of", "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", "Prims.unit", "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.MonotonicHigherReference.write", "Steel.Channel.Protocol.extension_of", "Steel.Channel.Simplex.next_trace_st", "Steel.Effect.Atomic.elim_pure", "Steel.MonotonicHigherReference.read_refine", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Channel.Simplex.trace_until", "Steel.Effect.Common.rmem", "Prims.l_True" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val update_trace (#p: _) (r: trace_ref p) (vr vs: chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True)
[]
Steel.Channel.Simplex.update_trace
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: Steel.Channel.Simplex.trace_ref p -> vr: Steel.Channel.Simplex.chan_val -> vs: Steel.Channel.Simplex.chan_val -> Steel.Effect.Steel Prims.unit
{ "end_col": 58, "end_line": 332, "start_col": 4, "start_line": 323 }
Steel.Effect.SteelT
val mk_chan (#p: prot) (send recv: ref chan_val) (v: init_chan_val p) : SteelT (chan_t_sr p send recv) ((pts_to send half v) `star` (pts_to recv half v)) (fun c -> chan_inv c)
[ { "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 } ]
false
let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c'
val mk_chan (#p: prot) (send recv: ref chan_val) (v: init_chan_val p) : SteelT (chan_t_sr p send recv) ((pts_to send half v) `star` (pts_to recv half v)) (fun c -> chan_inv c) let mk_chan (#p: prot) (send recv: ref chan_val) (v: init_chan_val p) : SteelT (chan_t_sr p send recv) ((pts_to send half v) `star` (pts_to recv half v)) (fun c -> chan_inv c) =
true
null
false
let tr:trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop ((pts_to send half v) `star` (pts_to recv half v)) ((pts_to c.send half v) `star` (pts_to c.recv half v)) (fun _ -> ()); intro_chan_inv #p c v; let c':chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c'
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.HigherReference.ref", "Steel.Channel.Simplex.chan_val", "Steel.Channel.Simplex.init_chan_val", "Steel.Effect.Atomic.return", "Steel.Channel.Simplex.chan_t_sr", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.chan_inv", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Memory.mem", "Steel.Channel.Simplex.intro_chan_inv", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.intro_trace_until_init", "Steel.MonotonicHigherReference.pts_to", "Steel.Channel.Protocol.partial_trace_of", "Steel.Channel.Protocol.extended_to", "Steel.FractionalPermission.full_perm", "Steel.Channel.Simplex.initial_trace", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Channel.Simplex.chan_t", "Steel.Channel.Simplex.Mkchan_t", "Steel.Channel.Simplex.trace_ref", "Steel.MonotonicHigherReference.alloc", "Steel.MonotonicHigherReference.ref" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mk_chan (#p: prot) (send recv: ref chan_val) (v: init_chan_val p) : SteelT (chan_t_sr p send recv) ((pts_to send half v) `star` (pts_to recv half v)) (fun c -> chan_inv c)
[]
Steel.Channel.Simplex.mk_chan
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
send: Steel.HigherReference.ref Steel.Channel.Simplex.chan_val -> recv: Steel.HigherReference.ref Steel.Channel.Simplex.chan_val -> v: Steel.Channel.Simplex.init_chan_val p -> Steel.Effect.SteelT (Steel.Channel.Simplex.chan_t_sr p send recv)
{ "end_col": 13, "end_line": 214, "start_col": 3, "start_line": 201 }
Steel.Effect.SteelT
val send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x))
[ { "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.Atomic", "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 } ]
false
let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x )
val send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) let rec send (#p: prot) (c: chan p) (#next: prot{more next}) (x: msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) =
true
null
false
let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then (rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) ()) else (rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x)
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan", "Prims.b2t", "Steel.Channel.Protocol.more", "Steel.Channel.Protocol.msg_t", "Prims.op_Equality", "Prims.nat", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_ctr", "FStar.Pervasives.Native.fst", "Steel.Channel.Simplex.chan_val", "FStar.Pervasives.Native.snd", "Steel.Channel.Simplex.send_available", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Effect.Common.pure", "Prims.eq2", "Steel.Memory.mem", "Prims.bool", "Steel.Channel.Simplex.send", "Steel.SpinLock.release", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.intro_chan_inv_stepT", "Steel.Channel.Simplex.chan_inv_step", "FStar.Pervasives.Native.tuple2", "Steel.Channel.Simplex.send_receive_prelude", "Steel.Channel.Simplex.sender", "Steel.Channel.Simplex.step", "Steel.Effect.Common.vprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x))
[ "recursion" ]
Steel.Channel.Simplex.send
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan p -> x: Steel.Channel.Protocol.msg_t next -> Steel.Effect.SteelT Prims.unit
{ "end_col": 5, "end_line": 388, "start_col": 3, "start_line": 373 }
Steel.Effect.SteelT
val send_available: #p: sprot -> #q: _ -> cc: chan q -> x: msg_t p -> vs: chan_val -> vr: chan_val -> unit -> SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x))
[ { "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 } ]
false
let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock
val send_available: #p: sprot -> #q: _ -> cc: chan q -> x: msg_t p -> vs: chan_val -> vr: chan_val -> unit -> SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) let send_available (#p: sprot) #q (cc: chan q) (x: msg_t p) (vs: chan_val) (vr: chan_val) (_: unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) =
true
null
false
Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs: chan_val) -> (pts_to cc.chan_chan.send half next_vs) `star` (in_state_slprop (step p x) next_vs)); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.sprot", "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan", "Steel.Channel.Protocol.msg_t", "Steel.Channel.Simplex.chan_val", "Prims.unit", "Steel.SpinLock.release", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.intro_chan_inv_stepT", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__send", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.in_state_slprop", "Steel.Channel.Simplex.step", "Steel.Effect.Common.vprop", "Steel.HigherReference.share", "Steel.FractionalPermission.full_perm", "Steel.Channel.Simplex.update_channel", "Steel.Channel.Simplex.gather_r", "Steel.Effect.Atomic.elim_pure", "Prims.eq2", "Steel.Utils.rewrite", "Steel.Channel.Simplex.send_recv_in_sync", "Steel.Utils.extract_pure", "Steel.Channel.Simplex.send_pre_available", "Steel.Channel.Simplex.sender" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val send_available: #p: sprot -> #q: _ -> cc: chan q -> x: msg_t p -> vs: chan_val -> vr: chan_val -> unit -> SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x))
[]
Steel.Channel.Simplex.send_available
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
cc: Steel.Channel.Simplex.chan q -> x: Steel.Channel.Protocol.msg_t p -> vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> _: Prims.unit -> Steel.Effect.SteelT Prims.unit
{ "end_col": 39, "end_line": 293, "start_col": 4, "start_line": 285 }
Steel.Effect.SteelT
val recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x))
[ { "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.Atomic", "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 } ]
false
let rec recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) = let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) () )
val recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) let rec recv (#p: prot) (#next: prot{more next}) (c: chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x)) =
true
null
false
let v = send_receive_prelude c in if (fst v).chan_ctr = (snd v).chan_ctr then (rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); elim_pure (fst v == snd v); intro_chan_inv_eqT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; recv c) else (rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); recv_availableT c (fst v) (snd v) ())
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Prims.b2t", "Steel.Channel.Protocol.more", "Steel.Channel.Simplex.chan", "Prims.op_Equality", "Prims.nat", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_ctr", "FStar.Pervasives.Native.fst", "Steel.Channel.Simplex.chan_val", "FStar.Pervasives.Native.snd", "Steel.Channel.Simplex.recv", "Steel.Channel.Protocol.msg_t", "Prims.unit", "Steel.SpinLock.release", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.intro_chan_inv_eqT", "Steel.Effect.Atomic.elim_pure", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Prims.eq2", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Channel.Simplex.chan_inv_cond", "Steel.Effect.Common.pure", "Steel.Memory.mem", "Prims.bool", "Steel.Channel.Simplex.recv_availableT", "Steel.Channel.Simplex.chan_inv_step", "FStar.Pervasives.Native.tuple2", "Steel.Channel.Simplex.send_receive_prelude", "Steel.Channel.Simplex.receiver", "Steel.Channel.Simplex.step", "Steel.Effect.Common.vprop" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg #push-options "--ide_id_info_off" let send_receive_prelude (#p:prot) (cc:chan p) : SteelT (chan_val & chan_val) emp (fun v -> pts_to cc.chan_chan.send half (fst v) `star` pts_to cc.chan_chan.recv half (snd v) `star` trace_until cc.chan_chan.trace (snd v) `star` chan_inv_cond (fst v) (snd v)) = let c = cc.chan_chan in Steel.SpinLock.acquire cc.chan_lock; let vs = read_refine (chan_inv_recv cc.chan_chan) cc.chan_chan.send in let _ = witness_exists () in let vr = H.read cc.chan_chan.recv in rewrite_slprop (trace_until _ _ `star` chan_inv_cond _ _) (trace_until cc.chan_chan.trace vr `star` chan_inv_cond vs vr) (fun _ -> ()); return (vs, vr) let rec send (#p:prot) (c:chan p) (#next:prot{more next}) (x:msg_t next) : SteelT unit (sender c next) (fun _ -> sender c (step next x)) = let v = send_receive_prelude c in //matching v as vs,vr fails if (fst v).chan_ctr = (snd v).chan_ctr then ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (pure (fst v == snd v)) (fun _ -> ()); send_available c x (fst v) (snd v) () //TODO: inlining send_availableT here fails ) else ( rewrite_slprop (chan_inv_cond (fst v) (snd v)) (chan_inv_step (snd v) (fst v)) (fun _ -> ()); intro_chan_inv_stepT c.chan_chan (fst v) (snd v); Steel.SpinLock.release c.chan_lock; send c x ) let rec recv (#p:prot) (#next:prot{more next}) (c:chan p)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recv (#p:prot) (#next:prot{more next}) (c:chan p) : SteelT (msg_t next) (receiver c next) (fun x -> receiver c (step next x))
[ "recursion" ]
Steel.Channel.Simplex.recv
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Steel.Channel.Simplex.chan p -> Steel.Effect.SteelT (Steel.Channel.Protocol.msg_t next)
{ "end_col": 5, "end_line": 408, "start_col": 3, "start_line": 392 }
Steel.Effect.SteelT
val recv_availableT: #p: sprot -> #q: _ -> cc: chan q -> vs: chan_val -> vr: chan_val -> unit -> SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x))
[ { "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 } ]
false
let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) = elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg : msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs:chan_val) -> pts_to cc.chan_chan.recv half vs `star` in_state_slprop (step p vs_msg) vs); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg
val recv_availableT: #p: sprot -> #q: _ -> cc: chan q -> vs: chan_val -> vr: chan_val -> unit -> SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) let recv_availableT (#p: sprot) #q (cc: chan q) (vs: chan_val) (vr: chan_val) (_: unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x)) =
true
null
false
elim_pure (chan_inv_step_p vr vs); gather_r cc.chan_chan.recv vr; elim_pure (in_state_prop p vr); H.write cc.chan_chan.recv vs; H.share cc.chan_chan.recv; assert (vs.chan_prot == p); let vs_msg:msg_t p = vs.chan_msg in intro_pure (in_state_prop (step p vs_msg) vs); intro_exists vs (fun (vs: chan_val) -> (pts_to cc.chan_chan.recv half vs) `star` (in_state_slprop (step p vs_msg) vs)); update_trace cc.chan_chan.trace vr vs; intro_chan_inv cc.chan_chan vs; Steel.SpinLock.release cc.chan_lock; vs_msg
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.sprot", "Steel.Channel.Simplex.prot", "Steel.Channel.Simplex.chan", "Steel.Channel.Simplex.chan_val", "Prims.unit", "Steel.Channel.Protocol.msg_t", "Steel.SpinLock.release", "Steel.Channel.Simplex.chan_inv", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_chan", "Steel.Channel.Simplex.__proj__Mkchan__item__chan_lock", "Steel.Channel.Simplex.intro_chan_inv", "Steel.Channel.Simplex.update_trace", "Steel.Channel.Simplex.__proj__Mkchan_t__item__trace", "Steel.Effect.Atomic.intro_exists", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.__proj__Mkchan_t__item__recv", "Steel.Channel.Simplex.half", "Steel.Channel.Simplex.in_state_slprop", "Steel.Channel.Simplex.step", "Steel.Effect.Common.vprop", "Steel.Effect.Atomic.intro_pure", "Steel.Channel.Simplex.in_state_prop", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_msg", "Prims._assert", "Prims.eq2", "Steel.Channel.Simplex.__proj__Mkchan_val__item__chan_prot", "Steel.HigherReference.share", "Steel.FractionalPermission.full_perm", "Steel.HigherReference.write", "Steel.Effect.Atomic.elim_pure", "Steel.Channel.Simplex.gather_r", "Steel.Channel.Simplex.chan_inv_step_p", "Steel.Channel.Simplex.sender_ahead", "Steel.Channel.Simplex.receiver" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c' let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch [@@__reduce__] let send_recv_in_sync (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` pure (vs == vr) `star` in_state r p) [@@__reduce__] let sender_ahead (r:ref chan_val) (p:prot{more p}) #q (c:chan_t q) (vs vr:chan_val) : vprop = (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs `star` in_state r p) let update_channel (#p:sprot) #q (c:chan_t q) (x:msg_t p) (vs:chan_val) (r:ref chan_val) : SteelT chan_val (pts_to r full_perm vs `star` in_state_slprop p vs) (fun vs' -> pts_to r full_perm vs' `star` (in_state_slprop (step p x) vs' `star` chan_inv_step vs vs')) = elim_pure (in_state_prop p vs); let vs' = next_chan_val x vs in H.write r vs'; intro_pure (in_state_prop (step p x) vs'); intro_pure (chan_inv_step_p vs vs'); return vs' [@@__reduce__] let send_pre_available (p:sprot) #q (c:chan_t q) (vs vr:chan_val) = send_recv_in_sync c.send p c vs vr let gather_r (#p:sprot) (r:ref chan_val) (v:chan_val) : SteelT unit (pts_to r half v `star` in_state r p) (fun _ -> pts_to r full_perm v `star` in_state_slprop p v) = let v' = witness_exists () in H.higher_ref_pts_to_injective_eq #_ #_ #_ #_ #v #_ r; H.gather #_ #_ #half #half #v #v r; rewrite_slprop (pts_to r (sum_perm half half) v) (pts_to r full_perm v) (fun _ -> ()); rewrite_slprop (in_state_slprop p v') (in_state_slprop p v) (fun _ -> ()) let send_available (#p:sprot) #q (cc:chan q) (x:msg_t p) (vs vr:chan_val) (_:unit) : SteelT unit (send_pre_available p #q cc.chan_chan vs vr) (fun _ -> sender cc (step p x)) = Steel.Utils.extract_pure (vs == vr); Steel.Utils.rewrite #_ #(send_recv_in_sync cc.chan_chan.send p cc.chan_chan vs) vr vs; elim_pure (vs == vs); gather_r cc.chan_chan.send vs; let next_vs = update_channel cc.chan_chan x vs cc.chan_chan.send in H.share cc.chan_chan.send; intro_exists next_vs (fun (next_vs:chan_val) -> pts_to cc.chan_chan.send half next_vs `star` in_state_slprop (step p x) next_vs); intro_chan_inv_stepT cc.chan_chan next_vs vs; Steel.SpinLock.release cc.chan_lock let extensible (#p:prot) (x:partial_trace_of p) = P.more x.to let next_msg_t (#p:prot) (x:partial_trace_of p) = P.next_msg_t x.to let next_trace #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) (s:squash (until tr == step vr.chan_prot vr.chan_msg)) (_:squash (chan_inv_step_p vr vs)) : (ts:partial_trace_of p { until ts == step vs.chan_prot vs.chan_msg }) = let msg : next_msg_t tr = vs.chan_msg in assert (extensible tr); extend_partial_trace tr msg let next_trace_st #p (vr:chan_val) (vs:chan_val) (tr:partial_trace_of p) : Steel (extension_of tr) (chan_inv_step vr vs) (fun _ -> emp) (requires fun _ -> until tr == step vr.chan_prot vr.chan_msg) (ensures fun _ ts _ -> until ts == step vs.chan_prot vs.chan_msg) = elim_pure (chan_inv_step_p vr vs); let ts : extension_of tr = next_trace vr vs tr () () in return ts let update_trace #p (r:trace_ref p) (vr:chan_val) (vs:chan_val) : Steel unit (trace_until r vr) (fun _ -> trace_until r vs) (requires fun _ -> chan_inv_step_p vr vs) (ensures fun _ _ _ -> True) = intro_pure (chan_inv_step_p vr vs); let tr = MRef.read_refine r in elim_pure (until tr == step vr.chan_prot vr.chan_msg); let ts : extension_of tr = next_trace_st vr vs tr in MRef.write r ts; intro_pure (until ts == step vs.chan_prot vs.chan_msg); intro_exists ts (fun (ts:partial_trace_of p) -> MRef.pts_to r full_perm ts `star` pure (until ts == step vs.chan_prot vs.chan_msg)) let recv_availableT (#p:sprot) #q (cc:chan q) (vs vr:chan_val) (_:unit) : SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr)
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val recv_availableT: #p: sprot -> #q: _ -> cc: chan q -> vs: chan_val -> vr: chan_val -> unit -> SteelT (msg_t p) (sender_ahead cc.chan_chan.recv p cc.chan_chan vs vr) (fun x -> receiver cc (step p x))
[]
Steel.Channel.Simplex.recv_availableT
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
cc: Steel.Channel.Simplex.chan q -> vs: Steel.Channel.Simplex.chan_val -> vr: Steel.Channel.Simplex.chan_val -> _: Prims.unit -> Steel.Effect.SteelT (Steel.Channel.Protocol.msg_t p)
{ "end_col": 10, "end_line": 350, "start_col": 4, "start_line": 338 }
Steel.Effect.SteelT
val new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p)
[ { "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.Atomic", "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 } ]
false
let new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) = let q = msg unit p in let v : chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp : init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; (* TODO: use smt_fallback *) rewrite_slprop (pts_to send (half_perm full_perm) v `star` pts_to send (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v `star` pts_to recv (half_perm full_perm) v) (pts_to send half vp `star` pts_to send half vp `star` pts_to recv half vp `star` pts_to recv half vp) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch
val new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p) let new_chan (p: prot) : SteelT (chan p) emp (fun c -> (sender c p) `star` (receiver c p)) =
true
null
false
let q = msg unit p in let v:chan_val = { chan_prot = q; chan_msg = (); chan_ctr = 0 } in let vp:init_chan_val p = v in let send = H.alloc v in let recv = H.alloc v in H.share recv; H.share send; rewrite_slprop ((((pts_to send (half_perm full_perm) v) `star` (pts_to send (half_perm full_perm) v) ) `star` (pts_to recv (half_perm full_perm) v)) `star` (pts_to recv (half_perm full_perm) v)) ((((pts_to send half vp) `star` (pts_to send half vp)) `star` (pts_to recv half vp)) `star` (pts_to recv half vp)) (fun _ -> ()); let c = mk_chan send recv vp in intro_in_state send p vp; intro_in_state recv p vp; let l = Steel.SpinLock.new_lock (chan_inv c) in let ch = { chan_chan = c; chan_lock = l } in rewrite_slprop (in_state send p) (sender ch p) (fun _ -> ()); rewrite_slprop (in_state recv p) (receiver ch p) (fun _ -> ()); return ch
{ "checked_file": "Steel.Channel.Simplex.fst.checked", "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" }
[]
[ "Steel.Channel.Simplex.prot", "Steel.Effect.Atomic.return", "Steel.Channel.Simplex.chan", "FStar.Ghost.hide", "FStar.Set.set", "Steel.Memory.iname", "FStar.Set.empty", "Steel.Effect.Common.VStar", "Steel.Channel.Simplex.sender", "Steel.Channel.Simplex.receiver", "Steel.Effect.Common.vprop", "Prims.unit", "Steel.Effect.Atomic.rewrite_slprop", "Steel.Channel.Simplex.in_state", "Steel.Memory.mem", "Steel.Channel.Simplex.Mkchan", "Steel.SpinLock.lock", "Steel.Channel.Simplex.chan_inv", "Steel.SpinLock.new_lock", "Steel.Channel.Simplex.intro_in_state", "Steel.Channel.Simplex.chan_t_sr", "Steel.Channel.Simplex.mk_chan", "Steel.Effect.Common.star", "Steel.HigherReference.pts_to", "Steel.Channel.Simplex.chan_val", "Steel.FractionalPermission.half_perm", "Steel.FractionalPermission.full_perm", "Steel.Channel.Simplex.half", "Steel.HigherReference.share", "Steel.HigherReference.ref", "Steel.HigherReference.alloc", "Steel.Channel.Simplex.init_chan_val", "Steel.Channel.Simplex.Mkchan_val", "Steel.Channel.Protocol.prot", "Steel.Channel.Simplex.msg", "Prims.eqtype", "Steel.Effect.Common.emp" ]
[]
(* Copyright 2020 Microsoft Research Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *) module Steel.Channel.Simplex module P = Steel.Channel.Protocol open Steel.SpinLock open Steel.Memory open Steel.Effect.Atomic open Steel.Effect open Steel.HigherReference open Steel.FractionalPermission module MRef = Steel.MonotonicHigherReference module H = Steel.HigherReference let sprot = p:prot { more p } noeq type chan_val = { chan_prot : sprot; chan_msg : msg_t chan_prot; chan_ctr : nat } let mref a p = MRef.ref a p let trace_ref (p:prot) = mref (partial_trace_of p) extended_to noeq type chan_t (p:prot) = { send: ref chan_val; recv: ref chan_val; trace: trace_ref p; } let half : perm = half_perm full_perm let step (s:sprot) (x:msg_t s) = step s x let chan_inv_step_p (vrecv vsend:chan_val) : prop = (vsend.chan_prot == step vrecv.chan_prot vrecv.chan_msg /\ vsend.chan_ctr == vrecv.chan_ctr + 1) let chan_inv_step (vrecv vsend:chan_val) : vprop = pure (chan_inv_step_p vrecv vsend) let chan_inv_cond (vsend:chan_val) (vrecv:chan_val) : vprop = if vsend.chan_ctr = vrecv.chan_ctr then pure (vsend == vrecv) else chan_inv_step vrecv vsend let trace_until_prop #p (r:trace_ref p) (vr:chan_val) (tr: partial_trace_of p) : vprop = MRef.pts_to r full_perm tr `star` pure (until tr == step vr.chan_prot vr.chan_msg) let trace_until #p (r:trace_ref p) (vr:chan_val) = h_exists (trace_until_prop r vr) let chan_inv_recv #p (c:chan_t p) (vsend:chan_val) = h_exists (fun (vrecv:chan_val) -> pts_to c.recv half vrecv `star` trace_until c.trace vrecv `star` chan_inv_cond vsend vrecv) let chan_inv #p (c:chan_t p) : vprop = h_exists (fun (vsend:chan_val) -> pts_to c.send half vsend `star` chan_inv_recv c vsend) let intro_chan_inv_cond_eqT (vs vr:chan_val) : Steel unit emp (fun _ -> chan_inv_cond vs vr) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_pure (vs == vs); rewrite_slprop (chan_inv_cond vs vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_cond_stepT (vs vr:chan_val) : SteelT unit (chan_inv_step vr vs) (fun _ -> chan_inv_cond vs vr) = Steel.Utils.extract_pure (chan_inv_step_p vr vs); rewrite_slprop (chan_inv_step vr vs) (chan_inv_cond vs vr) (fun _ -> ()) let intro_chan_inv_auxT #p (#vs : chan_val) (#vr : chan_val) (c:chan_t p) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr) (fun _ -> chan_inv c) = intro_exists _ (fun (vr:chan_val) -> pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_cond vs vr); intro_exists _ (fun (vs:chan_val) -> pts_to c.send half vs `star` chan_inv_recv c vs) let intro_chan_inv_stepT #p (c:chan_t p) (vs vr:chan_val) : SteelT unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr `star` chan_inv_step vr vs) (fun _ -> chan_inv c) = intro_chan_inv_cond_stepT vs vr; intro_chan_inv_auxT c let intro_chan_inv_eqT #p (c:chan_t p) (vs vr:chan_val) : Steel unit (pts_to c.send half vs `star` pts_to c.recv half vr `star` trace_until c.trace vr) (fun _ -> chan_inv c) (requires fun _ -> vs == vr) (ensures fun _ _ _ -> True) = intro_chan_inv_cond_eqT vs vr; intro_chan_inv_auxT c noeq type chan p = { chan_chan : chan_t p; chan_lock : lock (chan_inv chan_chan) } let in_state_prop (p:prot) (vsend:chan_val) : prop = p == step vsend.chan_prot vsend.chan_msg irreducible let next_chan_val (#p:sprot) (x:msg_t p) (vs0:chan_val { in_state_prop p vs0 }) : Tot (vs:chan_val{in_state_prop (step p x) vs /\ chan_inv_step_p vs0 vs}) = { chan_prot = (step vs0.chan_prot vs0.chan_msg); chan_msg = x; chan_ctr = vs0.chan_ctr + 1 } [@@__reduce__] let in_state_slprop (p:prot) (vsend:chan_val) : vprop = pure (in_state_prop p vsend) let in_state (r:ref chan_val) (p:prot) = h_exists (fun (vsend:chan_val) -> pts_to r half vsend `star` in_state_slprop p vsend) let sender #q (c:chan q) (p:prot) = in_state c.chan_chan.send p let receiver #q (c:chan q) (p:prot) = in_state c.chan_chan.recv p let intro_chan_inv #p (c:chan_t p) (v:chan_val) : SteelT unit (pts_to c.send half v `star` pts_to c.recv half v `star` trace_until c.trace v) (fun _ -> chan_inv c) = intro_chan_inv_eqT c v v let chan_val_p (p:prot) = (vs0:chan_val { in_state_prop p vs0 }) let intro_in_state (r:ref chan_val) (p:prot) (v:chan_val_p p) : SteelT unit (pts_to r half v) (fun _ -> in_state r p) = intro_pure (in_state_prop p v); intro_exists v (fun (v:chan_val) -> pts_to r half v `star` in_state_slprop p v) let msg t p = Msg Send unit (fun _ -> p) let init_chan_val (p:prot) = v:chan_val {v.chan_prot == msg unit p} let initial_trace (p:prot) : (q:partial_trace_of p {until q == p}) = { to = p; tr=Waiting p} let intro_trace_until #q (r:trace_ref q) (tr:partial_trace_of q) (v:chan_val) : Steel unit (MRef.pts_to r full_perm tr) (fun _ -> trace_until r v) (requires fun _ -> until tr == step v.chan_prot v.chan_msg) (ensures fun _ _ _ -> True) = intro_pure (until tr == step v.chan_prot v.chan_msg); intro_exists tr (fun (tr:partial_trace_of q) -> MRef.pts_to r full_perm tr `star` pure (until tr == (step v.chan_prot v.chan_msg))); () let chan_t_sr (p:prot) (send recv:ref chan_val) = (c:chan_t p{c.send == send /\ c.recv == recv}) let intro_trace_until_init #p (c:chan_t p) (v:init_chan_val p) : SteelT unit (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> trace_until c.trace v) = intro_pure (until (initial_trace p) == step v.chan_prot v.chan_msg); //TODO: Not sure why I need this rewrite rewrite_slprop (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (MRef.pts_to c.trace full_perm (initial_trace p) `star` pure (until (initial_trace p) == step v.chan_prot v.chan_msg)) (fun _ -> ()); intro_exists (initial_trace p) (trace_until_prop c.trace v) let mk_chan (#p:prot) (send recv:ref chan_val) (v:init_chan_val p) : SteelT (chan_t_sr p send recv) (pts_to send half v `star` pts_to recv half v) (fun c -> chan_inv c) = let tr: trace_ref p = MRef.alloc (extended_to #p) (initial_trace p) in let c = Mkchan_t send recv tr in rewrite_slprop (MRef.pts_to tr full_perm (initial_trace p)) (MRef.pts_to c.trace full_perm (initial_trace p)) (fun _ -> ()); intro_trace_until_init c v; rewrite_slprop (pts_to send half v `star` pts_to recv half v) (pts_to c.send half v `star` pts_to c.recv half v) (fun _ -> ()); intro_chan_inv #p c v; let c' : chan_t_sr p send recv = c in rewrite_slprop (chan_inv c) (chan_inv c') (fun _ -> ()); return c'
false
false
Steel.Channel.Simplex.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val new_chan (p:prot) : SteelT (chan p) emp (fun c -> sender c p `star` receiver c p)
[]
Steel.Channel.Simplex.new_chan
{ "file_name": "lib/steel/Steel.Channel.Simplex.fst", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Steel.Channel.Simplex.prot -> Steel.Effect.SteelT (Steel.Channel.Simplex.chan p)
{ "end_col": 13, "end_line": 241, "start_col": 3, "start_line": 217 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let felem2 = lbuffer uint64 8ul
let felem2 =
false
null
false
lbuffer uint64 8ul
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul
false
true
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val felem2 : Type0
[]
Hacl.Impl.Curve25519.Field64.felem2
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 31, "end_line": 29, "start_col": 13, "start_line": 29 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let u512 = lbuffer uint64 8ul
let u512 =
false
null
false
lbuffer uint64 8ul
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val u512 : Type0
[]
Hacl.Impl.Curve25519.Field64.u512
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 29, "end_line": 25, "start_col": 11, "start_line": 25 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let felem = lbuffer uint64 4ul
let felem =
false
null
false
lbuffer uint64 4ul
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul
false
true
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val felem : Type0
[]
Hacl.Impl.Curve25519.Field64.felem
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 30, "end_line": 28, "start_col": 12, "start_line": 28 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let u1024 = lbuffer uint64 16ul
let u1024 =
false
null
false
lbuffer uint64 16ul
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul
false
true
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val u1024 : Type0
[]
Hacl.Impl.Curve25519.Field64.u1024
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 31, "end_line": 26, "start_col": 12, "start_line": 26 }
Prims.Tot
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let u256 = lbuffer uint64 4ul
let u256 =
false
null
false
lbuffer uint64 4ul
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "total" ]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
false
true
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val u256 : Type0
[]
Hacl.Impl.Curve25519.Field64.u256
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
Type0
{ "end_col": 29, "end_line": 24, "start_col": 11, "start_line": 24 }
Prims.GTot
val fevalh (h: mem) (f: felem) : GTot P.elem
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime
val fevalh (h: mem) (f: felem) : GTot P.elem let fevalh (h: mem) (f: felem) : GTot P.elem =
false
null
false
(as_nat h f) % P.prime
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "sometrivial" ]
[ "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Curve25519.Field64.felem", "Prims.op_Modulus", "Hacl.Impl.Curve25519.Field64.as_nat", "Spec.Curve25519.prime", "Spec.Curve25519.elem" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3)
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val fevalh (h: mem) (f: felem) : GTot P.elem
[]
Hacl.Impl.Curve25519.Field64.fevalh
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: FStar.Monotonic.HyperStack.mem -> f: Hacl.Impl.Curve25519.Field64.felem -> Prims.GTot Spec.Curve25519.elem
{ "end_col": 67, "end_line": 41, "start_col": 45, "start_line": 41 }
Prims.GTot
val as_nat (h: mem) (e: felem) : GTot nat
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3)
val as_nat (h: mem) (e: felem) : GTot nat let as_nat (h: mem) (e: felem) : GTot nat =
false
null
false
let s = as_seq h e in let s0 = s.[ 0 ] in let s1 = s.[ 1 ] in let s2 = s.[ 2 ] in let s3 = s.[ 3 ] in S.as_nat4 (s0, s1, s2, s3)
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[ "sometrivial" ]
[ "FStar.Monotonic.HyperStack.mem", "Hacl.Impl.Curve25519.Field64.felem", "Hacl.Spec.Curve25519.Field64.Definition.as_nat4", "FStar.Pervasives.Native.Mktuple4", "Lib.IntTypes.uint64", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Prims.eq2", "FStar.Seq.Base.index", "Lib.Sequence.to_seq", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.uint_to_t", "FStar.UInt32.t", "Lib.Sequence.op_String_Access", "FStar.UInt32.__uint_to_t", "Lib.Sequence.lseq", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.nat" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val as_nat (h: mem) (e: felem) : GTot nat
[]
Hacl.Impl.Curve25519.Field64.as_nat
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
h: FStar.Monotonic.HyperStack.mem -> e: Hacl.Impl.Curve25519.Field64.felem -> Prims.GTot Prims.nat
{ "end_col": 28, "end_line": 38, "start_col": 41, "start_line": 32 }
FStar.HyperStack.ST.Stack
val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let load_felem f u64s = let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul)
val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem f u64s =
true
null
false
let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul)
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Hacl.Impl.Curve25519.Field64.felem", "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.Buffer.op_Array_Assignment", "Prims.unit", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access", "Lib.Buffer.MUT", "Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4", "Lib.Buffer.as_seq", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 4ul (u64 0) inline_for_extraction noextract val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s))
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s))
[]
Hacl.Impl.Curve25519.Field64.load_felem
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: Hacl.Impl.Curve25519.Field64.felem -> u64s: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 23, "end_line": 72, "start_col": 23, "start_line": 66 }
FStar.HyperStack.ST.Stack
val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let set_zero f = f.(0ul) <- u64 0; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0
val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero f =
true
null
false
f.(0ul) <- u64 0; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Hacl.Impl.Curve25519.Field64.felem", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Prims.unit" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 4ul (u64 0) inline_for_extraction noextract val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem f u64s = let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul) val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f)) [@ Meta.Attribute.inline_ ] let carry_pass_store f = let f3 = f.(3ul) in let top_bit = f3 >>. 63ul in f.(3ul) <- f3 &. u64 0x7fffffffffffffff; let h0 = ST.get () in let carry = add1 f f (u64 19 *! top_bit) in let h1 = ST.get () in assert (as_nat h1 f + v carry * pow2 256 == as_nat h0 f + 19 * v top_bit); S.bn_v_is_as_nat (as_seq h1 f); S.bn_v_is_as_nat (as_seq h0 f); let cr = Ghost.hide (Hacl.Spec.Curve25519.Field64.Core.add1 (as_seq h0 f) (u64 19 *! top_bit)) in SD.bn_eval_bound (snd cr) 4; assert (v (fst cr) == v carry /\ SD.bn_v (snd cr) == as_nat h1 f); SD.bn_eval_inj 4 (snd cr) (as_seq h1 f); () val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f)) [@ Meta.Attribute.inline_ ] let store_felem u64s f = let h0 = ST.get () in carry_pass_store f; let h1 = ST.get () in SC.lemma_carry_pass_store_first (as_seq h0 f); carry_pass_store f; let h2 = ST.get () in SC.lemma_carry_pass_store_second (as_seq h1 f); let f0 = f.(0ul) in let f1 = f.(1ul) in let f2 = f.(2ul) in let f3 = f.(3ul) in S.bn_v_is_as_nat (as_seq h0 f); S.bn_v_is_as_nat (as_seq h2 f); let (o0, o1, o2, o3) = SC.subtract_p4 (f0, f1, f2, f3) in assert (S.as_nat4 (o0, o1, o2, o3) < P.prime); assert (S.as_nat4 (o0, o1, o2, o3) == (as_nat h2 f) % P.prime); u64s.(0ul) <- o0; u64s.(1ul) <- o1; u64s.(2ul) <- o2; u64s.(3ul) <- o3; let h3 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h3 u64s); BSeq.lemma_nat_from_to_intseq_le_preserves_value 4 (as_seq h3 u64s) inline_for_extraction noextract val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0)
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0)
[]
Hacl.Impl.Curve25519.Field64.set_zero
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: Hacl.Impl.Curve25519.Field64.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 18, "end_line": 149, "start_col": 2, "start_line": 146 }
FStar.HyperStack.ST.Stack
val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let set_one f = f.(0ul) <- u64 1; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0
val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1) let set_one f =
true
null
false
f.(0ul) <- u64 1; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Hacl.Impl.Curve25519.Field64.felem", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Prims.unit" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 4ul (u64 0) inline_for_extraction noextract val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem f u64s = let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul) val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f)) [@ Meta.Attribute.inline_ ] let carry_pass_store f = let f3 = f.(3ul) in let top_bit = f3 >>. 63ul in f.(3ul) <- f3 &. u64 0x7fffffffffffffff; let h0 = ST.get () in let carry = add1 f f (u64 19 *! top_bit) in let h1 = ST.get () in assert (as_nat h1 f + v carry * pow2 256 == as_nat h0 f + 19 * v top_bit); S.bn_v_is_as_nat (as_seq h1 f); S.bn_v_is_as_nat (as_seq h0 f); let cr = Ghost.hide (Hacl.Spec.Curve25519.Field64.Core.add1 (as_seq h0 f) (u64 19 *! top_bit)) in SD.bn_eval_bound (snd cr) 4; assert (v (fst cr) == v carry /\ SD.bn_v (snd cr) == as_nat h1 f); SD.bn_eval_inj 4 (snd cr) (as_seq h1 f); () val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f)) [@ Meta.Attribute.inline_ ] let store_felem u64s f = let h0 = ST.get () in carry_pass_store f; let h1 = ST.get () in SC.lemma_carry_pass_store_first (as_seq h0 f); carry_pass_store f; let h2 = ST.get () in SC.lemma_carry_pass_store_second (as_seq h1 f); let f0 = f.(0ul) in let f1 = f.(1ul) in let f2 = f.(2ul) in let f3 = f.(3ul) in S.bn_v_is_as_nat (as_seq h0 f); S.bn_v_is_as_nat (as_seq h2 f); let (o0, o1, o2, o3) = SC.subtract_p4 (f0, f1, f2, f3) in assert (S.as_nat4 (o0, o1, o2, o3) < P.prime); assert (S.as_nat4 (o0, o1, o2, o3) == (as_nat h2 f) % P.prime); u64s.(0ul) <- o0; u64s.(1ul) <- o1; u64s.(2ul) <- o2; u64s.(3ul) <- o3; let h3 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h3 u64s); BSeq.lemma_nat_from_to_intseq_le_preserves_value 4 (as_seq h3 u64s) inline_for_extraction noextract val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero f = f.(0ul) <- u64 0; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0 inline_for_extraction noextract val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1)
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1)
[]
Hacl.Impl.Curve25519.Field64.set_one
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: Hacl.Impl.Curve25519.Field64.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 18, "end_line": 164, "start_col": 2, "start_line": 161 }
FStar.HyperStack.ST.Stack
val copy_felem: f1:felem -> f2:felem -> Stack unit (requires fun h -> live h f1 /\ live h f2 /\ disjoint f1 f2) (ensures fun h0 _ h1 -> modifies (loc f1) h0 h1 /\ as_seq h1 f1 == as_seq h0 f2)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let copy_felem f1 f2 = f1.(0ul) <- f2.(0ul); f1.(1ul) <- f2.(1ul); f1.(2ul) <- f2.(2ul); f1.(3ul) <- f2.(3ul); let h1 = ST.get () in LSeq.eq_intro (as_seq h1 f1) (as_seq h1 f2)
val copy_felem: f1:felem -> f2:felem -> Stack unit (requires fun h -> live h f1 /\ live h f2 /\ disjoint f1 f2) (ensures fun h0 _ h1 -> modifies (loc f1) h0 h1 /\ as_seq h1 f1 == as_seq h0 f2) let copy_felem f1 f2 =
true
null
false
f1.(0ul) <- f2.(0ul); f1.(1ul) <- f2.(1ul); f1.(2ul) <- f2.(2ul); f1.(3ul) <- f2.(3ul); let h1 = ST.get () in LSeq.eq_intro (as_seq h1 f1) (as_seq h1 f2)
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Hacl.Impl.Curve25519.Field64.felem", "Lib.Sequence.eq_intro", "Lib.IntTypes.uint64", "Lib.IntTypes.v", "Lib.IntTypes.U32", "Lib.IntTypes.PUB", "FStar.UInt32.__uint_to_t", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.int_t", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.op_Array_Access" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 4ul (u64 0) inline_for_extraction noextract val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem f u64s = let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul) val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f)) [@ Meta.Attribute.inline_ ] let carry_pass_store f = let f3 = f.(3ul) in let top_bit = f3 >>. 63ul in f.(3ul) <- f3 &. u64 0x7fffffffffffffff; let h0 = ST.get () in let carry = add1 f f (u64 19 *! top_bit) in let h1 = ST.get () in assert (as_nat h1 f + v carry * pow2 256 == as_nat h0 f + 19 * v top_bit); S.bn_v_is_as_nat (as_seq h1 f); S.bn_v_is_as_nat (as_seq h0 f); let cr = Ghost.hide (Hacl.Spec.Curve25519.Field64.Core.add1 (as_seq h0 f) (u64 19 *! top_bit)) in SD.bn_eval_bound (snd cr) 4; assert (v (fst cr) == v carry /\ SD.bn_v (snd cr) == as_nat h1 f); SD.bn_eval_inj 4 (snd cr) (as_seq h1 f); () val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f)) [@ Meta.Attribute.inline_ ] let store_felem u64s f = let h0 = ST.get () in carry_pass_store f; let h1 = ST.get () in SC.lemma_carry_pass_store_first (as_seq h0 f); carry_pass_store f; let h2 = ST.get () in SC.lemma_carry_pass_store_second (as_seq h1 f); let f0 = f.(0ul) in let f1 = f.(1ul) in let f2 = f.(2ul) in let f3 = f.(3ul) in S.bn_v_is_as_nat (as_seq h0 f); S.bn_v_is_as_nat (as_seq h2 f); let (o0, o1, o2, o3) = SC.subtract_p4 (f0, f1, f2, f3) in assert (S.as_nat4 (o0, o1, o2, o3) < P.prime); assert (S.as_nat4 (o0, o1, o2, o3) == (as_nat h2 f) % P.prime); u64s.(0ul) <- o0; u64s.(1ul) <- o1; u64s.(2ul) <- o2; u64s.(3ul) <- o3; let h3 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h3 u64s); BSeq.lemma_nat_from_to_intseq_le_preserves_value 4 (as_seq h3 u64s) inline_for_extraction noextract val set_zero: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 0) let set_zero f = f.(0ul) <- u64 0; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0 inline_for_extraction noextract val set_one: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == 1) let set_one f = f.(0ul) <- u64 1; f.(1ul) <- u64 0; f.(2ul) <- u64 0; f.(3ul) <- u64 0 inline_for_extraction noextract val copy_felem: f1:felem -> f2:felem -> Stack unit (requires fun h -> live h f1 /\ live h f2 /\ disjoint f1 f2) (ensures fun h0 _ h1 -> modifies (loc f1) h0 h1 /\ as_seq h1 f1 == as_seq h0 f2)
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val copy_felem: f1:felem -> f2:felem -> Stack unit (requires fun h -> live h f1 /\ live h f2 /\ disjoint f1 f2) (ensures fun h0 _ h1 -> modifies (loc f1) h0 h1 /\ as_seq h1 f1 == as_seq h0 f2)
[]
Hacl.Impl.Curve25519.Field64.copy_felem
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f1: Hacl.Impl.Curve25519.Field64.felem -> f2: Hacl.Impl.Curve25519.Field64.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 45, "end_line": 184, "start_col": 2, "start_line": 179 }
FStar.HyperStack.ST.StackInline
val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0)
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let create_felem () = create 4ul (u64 0)
val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () =
true
null
false
create 4ul (u64 0)
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Prims.unit", "Lib.Buffer.create", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Lib.IntTypes.u64", "Lib.Buffer.lbuffer", "Hacl.Impl.Curve25519.Field64.felem" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0)
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0)
[]
Hacl.Impl.Curve25519.Field64.create_felem
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
_: Prims.unit -> FStar.HyperStack.ST.StackInline Hacl.Impl.Curve25519.Field64.felem
{ "end_col": 40, "end_line": 52, "start_col": 22, "start_line": 52 }
FStar.HyperStack.ST.Stack
val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let carry_pass_store f = let f3 = f.(3ul) in let top_bit = f3 >>. 63ul in f.(3ul) <- f3 &. u64 0x7fffffffffffffff; let h0 = ST.get () in let carry = add1 f f (u64 19 *! top_bit) in let h1 = ST.get () in assert (as_nat h1 f + v carry * pow2 256 == as_nat h0 f + 19 * v top_bit); S.bn_v_is_as_nat (as_seq h1 f); S.bn_v_is_as_nat (as_seq h0 f); let cr = Ghost.hide (Hacl.Spec.Curve25519.Field64.Core.add1 (as_seq h0 f) (u64 19 *! top_bit)) in SD.bn_eval_bound (snd cr) 4; assert (v (fst cr) == v carry /\ SD.bn_v (snd cr) == as_nat h1 f); SD.bn_eval_inj 4 (snd cr) (as_seq h1 f); ()
val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f)) let carry_pass_store f =
true
null
false
let f3 = f.(3ul) in let top_bit = f3 >>. 63ul in f.(3ul) <- f3 &. u64 0x7fffffffffffffff; let h0 = ST.get () in let carry = add1 f f (u64 19 *! top_bit) in let h1 = ST.get () in assert (as_nat h1 f + v carry * pow2 256 == as_nat h0 f + 19 * v top_bit); S.bn_v_is_as_nat (as_seq h1 f); S.bn_v_is_as_nat (as_seq h0 f); let cr = Ghost.hide (Hacl.Spec.Curve25519.Field64.Core.add1 (as_seq h0 f) (u64 19 *! top_bit)) in SD.bn_eval_bound (snd cr) 4; assert (v (fst cr) == v carry /\ SD.bn_v (snd cr) == as_nat h1 f); SD.bn_eval_inj 4 (snd cr) (as_seq h1 f); ()
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Hacl.Impl.Curve25519.Field64.felem", "Prims.unit", "Hacl.Spec.Bignum.Definitions.bn_eval_inj", "Lib.IntTypes.U64", "FStar.Pervasives.Native.snd", "Lib.IntTypes.uint64", "Hacl.Spec.Curve25519.Field64.Core.felem", "FStar.Ghost.reveal", "FStar.Pervasives.Native.tuple2", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "FStar.UInt32.__uint_to_t", "Prims._assert", "Prims.l_and", "Prims.eq2", "Lib.IntTypes.range_t", "Lib.IntTypes.v", "Lib.IntTypes.SEC", "FStar.Pervasives.Native.fst", "Prims.nat", "Hacl.Spec.Bignum.Definitions.bn_v", "Hacl.Impl.Curve25519.Field64.as_nat", "Hacl.Spec.Bignum.Definitions.bn_eval_bound", "FStar.Ghost.erased", "Lib.IntTypes.int_t", "Hacl.Spec.Bignum.Definitions.lbignum", "FStar.Ghost.hide", "Hacl.Spec.Curve25519.Field64.Core.add1", "Lib.IntTypes.op_Star_Bang", "Lib.IntTypes.u64", "Hacl.Spec.Curve25519.Field64.Definition.bn_v_is_as_nat", "Prims.int", "Prims.op_Addition", "FStar.Mul.op_Star", "Prims.pow2", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Hacl.Impl.Curve25519.Fields.Core.add1", "Lib.Buffer.op_Array_Assignment", "Lib.IntTypes.op_Amp_Dot", "Lib.IntTypes.op_Greater_Greater_Dot", "Lib.Buffer.op_Array_Access" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 4ul (u64 0) inline_for_extraction noextract val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem f u64s = let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul) val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f))
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f))
[]
Hacl.Impl.Curve25519.Field64.carry_pass_store
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
f: Hacl.Impl.Curve25519.Field64.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 4, "end_line": 97, "start_col": 24, "start_line": 83 }
FStar.HyperStack.ST.Stack
val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f))
[ { "abbrev": true, "full_module": "Hacl.Spec.Bignum.Definitions", "short_module": "SD" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64", "short_module": "SC" }, { "abbrev": true, "full_module": "Hacl.Spec.Curve25519.Field64.Definition", "short_module": "S" }, { "abbrev": true, "full_module": "Spec.Curve25519", "short_module": "P" }, { "abbrev": true, "full_module": "Lib.ByteSequence", "short_module": "BSeq" }, { "abbrev": true, "full_module": "Lib.Sequence", "short_module": "LSeq" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "ST" }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519.Fields.Core", "short_module": null }, { "abbrev": false, "full_module": "Lib.Buffer", "short_module": null }, { "abbrev": false, "full_module": "Lib.IntTypes", "short_module": null }, { "abbrev": false, "full_module": "Lib.Sequence", "short_module": null }, { "abbrev": false, "full_module": "FStar.Mul", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack.All", "short_module": null }, { "abbrev": false, "full_module": "FStar.HyperStack", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "Hacl.Impl.Curve25519", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let store_felem u64s f = let h0 = ST.get () in carry_pass_store f; let h1 = ST.get () in SC.lemma_carry_pass_store_first (as_seq h0 f); carry_pass_store f; let h2 = ST.get () in SC.lemma_carry_pass_store_second (as_seq h1 f); let f0 = f.(0ul) in let f1 = f.(1ul) in let f2 = f.(2ul) in let f3 = f.(3ul) in S.bn_v_is_as_nat (as_seq h0 f); S.bn_v_is_as_nat (as_seq h2 f); let (o0, o1, o2, o3) = SC.subtract_p4 (f0, f1, f2, f3) in assert (S.as_nat4 (o0, o1, o2, o3) < P.prime); assert (S.as_nat4 (o0, o1, o2, o3) == (as_nat h2 f) % P.prime); u64s.(0ul) <- o0; u64s.(1ul) <- o1; u64s.(2ul) <- o2; u64s.(3ul) <- o3; let h3 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h3 u64s); BSeq.lemma_nat_from_to_intseq_le_preserves_value 4 (as_seq h3 u64s)
val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f)) let store_felem u64s f =
true
null
false
let h0 = ST.get () in carry_pass_store f; let h1 = ST.get () in SC.lemma_carry_pass_store_first (as_seq h0 f); carry_pass_store f; let h2 = ST.get () in SC.lemma_carry_pass_store_second (as_seq h1 f); let f0 = f.(0ul) in let f1 = f.(1ul) in let f2 = f.(2ul) in let f3 = f.(3ul) in S.bn_v_is_as_nat (as_seq h0 f); S.bn_v_is_as_nat (as_seq h2 f); let o0, o1, o2, o3 = SC.subtract_p4 (f0, f1, f2, f3) in assert (S.as_nat4 (o0, o1, o2, o3) < P.prime); assert (S.as_nat4 (o0, o1, o2, o3) == (as_nat h2 f) % P.prime); u64s.(0ul) <- o0; u64s.(1ul) <- o1; u64s.(2ul) <- o2; u64s.(3ul) <- o3; let h3 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h3 u64s); BSeq.lemma_nat_from_to_intseq_le_preserves_value 4 (as_seq h3 u64s)
{ "checked_file": "Hacl.Impl.Curve25519.Field64.fst.checked", "dependencies": [ "Spec.Curve25519.fst.checked", "prims.fst.checked", "Meta.Attribute.fst.checked", "Lib.Sequence.fsti.checked", "Lib.IntTypes.fsti.checked", "Lib.ByteSequence.fsti.checked", "Lib.Buffer.fsti.checked", "Hacl.Spec.Curve25519.Field64.Definition.fst.checked", "Hacl.Spec.Curve25519.Field64.Core.fst.checked", "Hacl.Spec.Curve25519.Field64.fst.checked", "Hacl.Spec.Bignum.Definitions.fst.checked", "Hacl.Impl.Curve25519.Lemmas.fst.checked", "Hacl.Impl.Curve25519.Fields.Core.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Mul.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.All.fst.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked" ], "interface_file": false, "source_file": "Hacl.Impl.Curve25519.Field64.fst" }
[]
[ "Lib.Buffer.lbuffer", "Lib.IntTypes.uint64", "FStar.UInt32.__uint_to_t", "Hacl.Impl.Curve25519.Field64.felem", "Lib.ByteSequence.lemma_nat_from_to_intseq_le_preserves_value", "Lib.IntTypes.U64", "Lib.IntTypes.SEC", "Lib.Buffer.as_seq", "Lib.Buffer.MUT", "Prims.unit", "Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "Lib.Buffer.op_Array_Assignment", "Prims._assert", "Prims.eq2", "Prims.int", "Hacl.Spec.Curve25519.Field64.Definition.as_nat4", "FStar.Pervasives.Native.Mktuple4", "Prims.op_Modulus", "Hacl.Impl.Curve25519.Field64.as_nat", "Spec.Curve25519.prime", "Prims.b2t", "Prims.op_LessThan", "Hacl.Spec.Curve25519.Field64.Definition.felem4", "Hacl.Spec.Curve25519.Field64.subtract_p4", "Hacl.Spec.Curve25519.Field64.Definition.bn_v_is_as_nat", "Lib.IntTypes.int_t", "Lib.Buffer.op_Array_Access", "Hacl.Spec.Curve25519.Field64.lemma_carry_pass_store_second", "Hacl.Impl.Curve25519.Field64.carry_pass_store", "Hacl.Spec.Curve25519.Field64.lemma_carry_pass_store_first" ]
[]
module Hacl.Impl.Curve25519.Field64 open FStar.HyperStack open FStar.HyperStack.All open FStar.Mul open Lib.Sequence open Lib.IntTypes open Lib.Buffer open Hacl.Impl.Curve25519.Fields.Core module ST = FStar.HyperStack.ST module LSeq = Lib.Sequence module BSeq = Lib.ByteSequence module P = Spec.Curve25519 module S = Hacl.Spec.Curve25519.Field64.Definition module SC = Hacl.Spec.Curve25519.Field64 module SD = Hacl.Spec.Bignum.Definitions #reset-options "--z3rlimit 50 --fuel 0 --ifuel 0" let u256 = lbuffer uint64 4ul let u512 = lbuffer uint64 8ul let u1024 = lbuffer uint64 16ul let felem = lbuffer uint64 4ul let felem2 = lbuffer uint64 8ul noextract let as_nat (h:mem) (e:felem) : GTot nat = let s = as_seq h e in let s0 = s.[0] in let s1 = s.[1] in let s2 = s.[2] in let s3 = s.[3] in S.as_nat4 (s0, s1, s2, s3) noextract let fevalh (h:mem) (f:felem) : GTot P.elem = (as_nat h f) % P.prime inline_for_extraction noextract val create_felem: unit -> StackInline felem (requires fun _ -> True) (ensures fun h0 f h1 -> stack_allocated f h0 h1 (Seq.create 4 (u64 0)) /\ as_nat h1 f == 0) let create_felem () = create 4ul (u64 0) inline_for_extraction noextract val load_felem: f:felem -> u64s:lbuffer uint64 4ul -> Stack unit (requires fun h -> live h u64s /\ live h f /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_nat h1 f == BSeq.nat_from_intseq_le (as_seq h0 u64s)) let load_felem f u64s = let h0 = ST.get () in Hacl.Impl.Curve25519.Lemmas.lemma_nat_from_uints64_le_4 (as_seq h0 u64s); f.(0ul) <- u64s.(0ul); f.(1ul) <- u64s.(1ul); f.(2ul) <- u64s.(2ul); f.(3ul) <- u64s.(3ul) val carry_pass_store: f:felem -> Stack unit (requires fun h -> live h f) (ensures fun h0 _ h1 -> modifies (loc f) h0 h1 /\ as_seq h1 f == SC.carry_pass_store (as_seq h0 f)) [@ Meta.Attribute.inline_ ] let carry_pass_store f = let f3 = f.(3ul) in let top_bit = f3 >>. 63ul in f.(3ul) <- f3 &. u64 0x7fffffffffffffff; let h0 = ST.get () in let carry = add1 f f (u64 19 *! top_bit) in let h1 = ST.get () in assert (as_nat h1 f + v carry * pow2 256 == as_nat h0 f + 19 * v top_bit); S.bn_v_is_as_nat (as_seq h1 f); S.bn_v_is_as_nat (as_seq h0 f); let cr = Ghost.hide (Hacl.Spec.Curve25519.Field64.Core.add1 (as_seq h0 f) (u64 19 *! top_bit)) in SD.bn_eval_bound (snd cr) 4; assert (v (fst cr) == v carry /\ SD.bn_v (snd cr) == as_nat h1 f); SD.bn_eval_inj 4 (snd cr) (as_seq h1 f); () val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f))
false
false
Hacl.Impl.Curve25519.Field64.fst
{ "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" }
null
val store_felem: u64s:lbuffer uint64 4ul -> f:felem -> Stack unit (requires fun h -> live h f /\ live h u64s /\ disjoint u64s f) (ensures fun h0 _ h1 -> modifies (loc u64s |+| loc f) h0 h1 /\ as_seq h1 u64s == BSeq.nat_to_intseq_le 4 (fevalh h0 f))
[]
Hacl.Impl.Curve25519.Field64.store_felem
{ "file_name": "code/curve25519/Hacl.Impl.Curve25519.Field64.fst", "git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e", "git_url": "https://github.com/hacl-star/hacl-star.git", "project_name": "hacl-star" }
u64s: Lib.Buffer.lbuffer Lib.IntTypes.uint64 4ul -> f: Hacl.Impl.Curve25519.Field64.felem -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 69, "end_line": 134, "start_col": 24, "start_line": 111 }
Prims.Tot
val eloc_includes (l1 l2: eloc) : Tot prop
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let eloc_includes (l1 l2:eloc) = B.loc_includes l1 l2 /\ True
val eloc_includes (l1 l2: eloc) : Tot prop let eloc_includes (l1 l2: eloc) =
false
null
false
B.loc_includes l1 l2 /\ True
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.eloc", "Prims.l_and", "LowStar.Monotonic.Buffer.loc_includes", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "Prims.l_True", "Prims.prop" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eloc_includes (l1 l2: eloc) : Tot prop
[]
EverParse3d.Actions.Base.eloc_includes
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
l1: EverParse3d.Actions.Base.eloc -> l2: EverParse3d.Actions.Base.eloc -> Prims.prop
{ "end_col": 61, "end_line": 33, "start_col": 33, "start_line": 33 }
Prims.Tot
val validate_with_action_t (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (p:parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) : Type0
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_with_action_t p inv l allow_reading = validate_with_action_t' p inv l allow_reading
val validate_with_action_t (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (p:parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) : Type0 let validate_with_action_t p inv l allow_reading =
false
null
false
validate_with_action_t' p inv l allow_reading
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t'" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 )
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_with_action_t (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#t:Type) (p:parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) : Type0
[]
EverParse3d.Actions.Base.validate_with_action_t
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: EverParse3d.Prelude.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> l: EverParse3d.Actions.Base.eloc -> allow_reading: Prims.bool -> Type0
{ "end_col": 96, "end_line": 200, "start_col": 51, "start_line": 200 }
Prims.Tot
val inv_implies (inv0 inv1: slice_inv) : Tot prop
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h
val inv_implies (inv0 inv1: slice_inv) : Tot prop let inv_implies (inv0 inv1: slice_inv) =
false
null
false
forall i h. inv0 i h ==> inv1 i h
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.slice_inv", "Prims.l_Forall", "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "Prims.prop" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val inv_implies (inv0 inv1: slice_inv) : Tot prop
[]
EverParse3d.Actions.Base.inv_implies
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
inv0: EverParse3d.Actions.Base.slice_inv -> inv1: EverParse3d.Actions.Base.slice_inv -> Prims.prop
{ "end_col": 25, "end_line": 27, "start_col": 2, "start_line": 26 }
Prims.Tot
val eloc : Type0
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l })
val eloc : Type0 let eloc =
false
null
false
(l: FStar.Ghost.erased B.loc {B.address_liveness_insensitive_locs `B.loc_includes` l})
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "FStar.Ghost.erased", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "FStar.Ghost.reveal" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eloc : Type0
[]
EverParse3d.Actions.Base.eloc
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type0
{ "end_col": 99, "end_line": 30, "start_col": 11, "start_line": 30 }
Prims.Tot
val validate_with_success_action (name: string) (#nz:bool) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] l1:eloc) (#allow_reading:bool) (v1:validate_with_action_t p1 inv1 l1 allow_reading) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] l2:eloc) (#b:bool) (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (l1 `eloc_union` l2) false
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_with_success_action name v1 a = validate_with_success_action' name (validate_drop v1) a
val validate_with_success_action (name: string) (#nz:bool) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] l1:eloc) (#allow_reading:bool) (v1:validate_with_action_t p1 inv1 l1 allow_reading) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] l2:eloc) (#b:bool) (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (l1 `eloc_union` l2) false let validate_with_success_action name v1 a =
false
null
false
validate_with_success_action' name (validate_drop v1) a
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.action", "EverParse3d.Actions.Base.validate_with_success_action'", "EverParse3d.Actions.Base.validate_drop", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.eloc_union" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv l false) = if allow_reading then validate_drop_true v else v let validate_with_success_action
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_with_success_action (name: string) (#nz:bool) (#wk: _) (#k1:parser_kind nz wk) (#[@@@erasable] t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] l1:eloc) (#allow_reading:bool) (v1:validate_with_action_t p1 inv1 l1 allow_reading) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] l2:eloc) (#b:bool) (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (l1 `eloc_union` l2) false
[]
EverParse3d.Actions.Base.validate_with_success_action
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
name: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 l1 allow_reading -> a: EverParse3d.Actions.Base.action p1 inv2 l2 b Prims.bool -> EverParse3d.Actions.Base.validate_with_action_t p1 (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
{ "end_col": 57, "end_line": 288, "start_col": 2, "start_line": 288 }
Prims.Tot
[ { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let hinv = HS.mem -> Tot Type0
let hinv =
false
null
false
HS.mem -> Tot Type0
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "FStar.Monotonic.HyperStack.mem" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hinv : Type
[]
EverParse3d.Actions.Base.hinv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type
{ "end_col": 30, "end_line": 19, "start_col": 11, "start_line": 19 }
Prims.Tot
val validate_eta (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv l allow_reading) : Tot (validate_with_action_t p inv l allow_reading)
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_eta v = fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos
val validate_eta (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv l allow_reading) : Tot (validate_with_action_t p inv l allow_reading) let validate_eta v =
false
null
false
fun ctxt error_handler_fn sl pos -> v ctxt error_handler_fn sl pos
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "EverParse3d.InputStream.Base.footprint", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.Seq.Base.length", "EverParse3d.InputStream.Base.get_read", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.InputStream.Base.perm_footprint", "Prims.l_imp", "Prims.l_not", "EverParse3d.ErrorCode.is_error", "EverParse3d.ErrorCode.get_validator_error_pos", "EverParse3d.ErrorCode.is_success", "EverParse3d.Actions.Base.valid_length", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "EverParse3d.Actions.Base.valid_consumed", "Prims.logical", "Prims.op_disEquality", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "FStar.Pervasives.Native.uu___is_None", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv l allow_reading
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_eta (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv l allow_reading) : Tot (validate_with_action_t p inv l allow_reading)
[]
EverParse3d.Actions.Base.validate_eta
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
v: EverParse3d.Actions.Base.validate_with_action_t p inv l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t p inv l allow_reading
{ "end_col": 68, "end_line": 203, "start_col": 2, "start_line": 203 }
Prims.Tot
[ { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
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 liveness_inv =
false
null
false
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 }
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.hinv", "Prims.l_Forall", "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "Prims.l_imp", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val liveness_inv : Type
[]
EverParse3d.Actions.Base.liveness_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type
{ "end_col": 1, "end_line": 22, "start_col": 19, "start_line": 20 }
Prims.Tot
[ { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let mem_inv = liveness_inv
let mem_inv =
false
null
false
liveness_inv
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.liveness_inv" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mem_inv : Type
[]
EverParse3d.Actions.Base.mem_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type
{ "end_col": 27, "end_line": 23, "start_col": 15, "start_line": 23 }
Prims.Tot
val true_inv : slice_inv
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let true_inv : slice_inv = fun _ _ -> True
val true_inv : slice_inv let true_inv:slice_inv =
false
null
false
fun _ _ -> True
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "Prims.l_True", "EverParse3d.Actions.Base.slice_inv" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h.
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val true_inv : slice_inv
[]
EverParse3d.Actions.Base.true_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.slice_inv
{ "end_col": 42, "end_line": 28, "start_col": 27, "start_line": 28 }
Prims.Tot
val slice_inv : Type u#1
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let slice_inv = loc -> mem_inv
val slice_inv : Type u#1 let slice_inv =
false
null
false
loc -> mem_inv
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.mem_inv" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 }
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val slice_inv : Type u#1
[]
EverParse3d.Actions.Base.slice_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type
{ "end_col": 30, "end_line": 24, "start_col": 16, "start_line": 24 }
Prims.Tot
val eloc_union (l1 l2: eloc) : Tot eloc
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let eloc_union (l1 l2:eloc) : Tot eloc = B.loc_union l1 l2
val eloc_union (l1 l2: eloc) : Tot eloc let eloc_union (l1 l2: eloc) : Tot eloc =
false
null
false
B.loc_union l1 l2
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.eloc", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_union", "FStar.Ghost.reveal" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl h
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eloc_union (l1 l2: eloc) : Tot eloc
[]
EverParse3d.Actions.Base.eloc_union
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
l1: EverParse3d.Actions.Base.eloc -> l2: EverParse3d.Actions.Base.eloc -> EverParse3d.Actions.Base.eloc
{ "end_col": 58, "end_line": 31, "start_col": 41, "start_line": 31 }
Prims.Tot
val valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
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))
val valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop let valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop =
false
null
false
I.live sl h /\ Some? (LP.parse p (I.get_remaining sl h))
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Base.input_stream_inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Base.parse", "Prims.prop" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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)
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h: HS.mem) (sl: input_buffer_t) : Tot prop
[]
EverParse3d.Actions.Base.valid
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> h: FStar.Monotonic.HyperStack.mem -> sl: input_buffer_t -> Prims.prop
{ "end_col": 43, "end_line": 134, "start_col": 2, "start_line": 133 }
Prims.Tot
val ptr_inv (#a: _) (x: bpointer a) : Tot slice_inv
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let ptr_inv #a (x:B.pointer a) : slice_inv = fun (sl:_) h -> B.live h x
val ptr_inv (#a: _) (x: bpointer a) : Tot slice_inv let ptr_inv #a (x: B.pointer a) : slice_inv =
false
null
false
fun (sl: _) h -> B.live h x
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowStar.Buffer.pointer", "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "EverParse3d.Actions.Base.slice_inv" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = () let bpointer a = B.pointer a
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ptr_inv (#a: _) (x: bpointer a) : Tot slice_inv
[]
EverParse3d.Actions.Base.ptr_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.Actions.Base.bpointer a -> EverParse3d.Actions.Base.slice_inv
{ "end_col": 71, "end_line": 45, "start_col": 45, "start_line": 45 }
Prims.Tot
val valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
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
val valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop let valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop =
false
null
false
I.live sl h /\ I.live sl h' /\ (let s = I.get_remaining sl h in match LP.parse p s with | None -> False | Some (_, len) -> (I.get_remaining sl h') `Seq.equal` (Seq.slice s len (Seq.length s)))
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Base.input_stream_inst", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "LowParse.Spec.Base.parse", "Prims.l_False", "LowParse.Spec.Base.consumed_length", "FStar.Seq.Base.equal", "FStar.UInt8.t", "EverParse3d.InputStream.Base.get_remaining", "FStar.Seq.Base.slice", "FStar.Seq.Base.length", "Prims.logical", "FStar.Seq.Base.seq", "Prims.prop" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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)
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_consumed (#input_buffer_t: Type0) (#[tcresolve ()] inst: I.input_stream_inst input_buffer_t) (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (h h': HS.mem) (sl: input_buffer_t) : Tot prop
[]
EverParse3d.Actions.Base.valid_consumed
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> h: FStar.Monotonic.HyperStack.mem -> h': FStar.Monotonic.HyperStack.mem -> sl: input_buffer_t -> Prims.prop
{ "end_col": 5, "end_line": 102, "start_col": 2, "start_line": 94 }
Prims.Tot
val validate_ret : validate_with_action_t (parse_ret ()) true_inv eloc_none true
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_ret : validate_with_action_t (parse_ret ()) true_inv eloc_none true = fun ctxt error_handler_fn input input_length start_position -> start_position
val validate_ret : validate_with_action_t (parse_ret ()) true_inv eloc_none true let validate_ret:validate_with_action_t (parse_ret ()) true_inv eloc_none true =
false
null
false
fun ctxt error_handler_fn input input_length start_position -> start_position
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.ret_kind", "Prims.unit", "EverParse3d.Prelude.parse_ret", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_ret : validate_with_action_t (parse_ret ()) true_inv eloc_none true
[]
EverParse3d.Actions.Base.validate_ret
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_ret ()) EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.eloc_none true
{ "end_col": 18, "end_line": 321, "start_col": 4, "start_line": 320 }
Prims.Tot
val act_with_comment (s: string) (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#b:_) (res:Type) (a: action p inv l b res) : Tot (action p inv l b res)
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let act_with_comment s res a = fun ctxt sl pos posf -> LPL.comment s; a ctxt sl pos posf
val act_with_comment (s: string) (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#b:_) (res:Type) (a: action p inv l b res) : Tot (action p inv l b res) let act_with_comment s res a =
false
null
false
fun ctxt sl pos posf -> LPL.comment s; a ctxt sl pos posf
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "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.ErrorCode.pos_t", "Prims.unit", "LowParse.Low.Base.comment" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val act_with_comment (s: string) (#nz:bool) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#b:_) (res:Type) (a: action p inv l b res) : Tot (action p inv l b res)
[]
EverParse3d.Actions.Base.act_with_comment
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
s: Prims.string -> res: Type -> a: EverParse3d.Actions.Base.action p inv l b res -> EverParse3d.Actions.Base.action p inv l b res
{ "end_col": 20, "end_line": 210, "start_col": 2, "start_line": 208 }
Prims.Tot
val validate_total_constant_size_no_read (#nz #wk: _) (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv l: _) : Tot (validate_with_action_t p inv l true)
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv l
val validate_total_constant_size_no_read (#nz #wk: _) (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv l: _) : Tot (validate_with_action_t p inv l true) let validate_total_constant_size_no_read #nz #wk (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) inv l : Tot (validate_with_action_t p inv l true) =
false
null
false
validate_total_constant_size_no_read' p sz u inv l
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "FStar.UInt64.t", "Prims.unit", "Prims.l_and", "Prims.eq2", "FStar.Pervasives.Native.option", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_total_constant_size_no_read'", "EverParse3d.Actions.Base.validate_with_action_t" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_total_constant_size_no_read (#nz #wk: _) (#k: parser_kind nz wk) (#t: Type) (p: parser k t) (sz: U64.t) (u: unit { k.LP.parser_kind_high == Some k.LP.parser_kind_low /\ k.LP.parser_kind_low == U64.v sz /\ k.LP.parser_kind_metadata == Some LP.ParserKindMetadataTotal }) (inv l: _) : Tot (validate_with_action_t p inv l true)
[]
EverParse3d.Actions.Base.validate_total_constant_size_no_read
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: EverParse3d.Prelude.parser k t -> sz: FStar.UInt64.t -> u526: u529: Prims.unit { Mkparser_kind'?.parser_kind_high k == FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k) /\ Mkparser_kind'?.parser_kind_low k == FStar.UInt64.v sz /\ Mkparser_kind'?.parser_kind_metadata k == FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserKindMetadataTotal } -> inv: EverParse3d.Actions.Base.slice_inv -> l: EverParse3d.Actions.Base.eloc -> EverParse3d.Actions.Base.validate_with_action_t p inv l true
{ "end_col": 52, "end_line": 1075, "start_col": 2, "start_line": 1075 }
Prims.Tot
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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' (#k: LP.parser_kind) (#t: Type) (p: LP.parser k t) (inv: slice_inv) (l: eloc) (allow_reading: bool) =
false
null
false
#[tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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')) /\ (let s = I.get_remaining sl h in if LPE.is_success res then 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 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))))
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "Prims.l_and", "EverParse3d.InputStream.Base.live", "EverParse3d.InputStream.Base.footprint", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt64.n", "FStar.UInt64.v", "FStar.Seq.Base.length", "EverParse3d.InputStream.Base.get_read", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.InputStream.Base.perm_footprint", "Prims.l_imp", "Prims.l_not", "EverParse3d.ErrorCode.is_error", "EverParse3d.ErrorCode.get_validator_error_pos", "EverParse3d.ErrorCode.is_success", "EverParse3d.Actions.Base.valid_length", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "EverParse3d.Actions.Base.valid_consumed", "Prims.logical", "Prims.op_disEquality", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "FStar.Pervasives.Native.uu___is_None", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "LowParse.Spec.Base.parse", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_with_action_t' : p: LowParse.Spec.Base.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> l: EverParse3d.Actions.Base.eloc -> allow_reading: Prims.bool -> Type0
[]
EverParse3d.Actions.Base.validate_with_action_t'
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> l: EverParse3d.Actions.Base.eloc -> allow_reading: Prims.bool -> Type0
{ "end_col": 5, "end_line": 198, "start_col": 2, "start_line": 163 }
Prims.Tot
val read____UINT8BE : leaf_reader parse____UINT8BE
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read____UINT8BE : leaf_reader parse____UINT8BE = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
val read____UINT8BE : leaf_reader parse____UINT8BE let read____UINT8BE:leaf_reader parse____UINT8BE =
false
null
false
lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Int.read_u8", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT8BE", "EverParse3d.Prelude.___UINT8BE", "EverParse3d.Prelude.parse____UINT8BE" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read____UINT8BE : leaf_reader parse____UINT8BE
[]
EverParse3d.Actions.Base.read____UINT8BE
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT8BE
{ "end_col": 48, "end_line": 1359, "start_col": 2, "start_line": 1359 }
Prims.Tot
val validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1:parser_kind nz1 _) #t1 (#p1:parser k1 t1) #inv1 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2
val validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false let validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) #nz1 (#k1: parser_kind nz1 _) #t1 (#p1: parser k1 t1) #inv1 #l1 (v1: validate_with_action_t p1 inv1 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 #l2 #ar2 (v2: (x: refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) =
false
null
false
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 l1 r1 f v2 else validate_dep_pair_with_refinement' name1 v1 r1 f v2
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "Prims.string", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.weak_kind", "EverParse3d.Prelude.refine", "LowParse.Spec.Base.bool_and", "Prims.op_Equality", "FStar.Pervasives.Native.option", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "EverParse3d.Actions.Base.validate_dep_pair_with_refinement_total_zero_parser'", "EverParse3d.Actions.Base.validate_dep_pair_with_refinement'", "Prims.op_BarBar", "EverParse3d.Kinds.and_then_kind", "EverParse3d.Kinds.filter_kind", "Prims.dtuple2", "EverParse3d.Prelude.parse_dep_pair", "EverParse3d.Prelude.parse_filter", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.eloc_union" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_dep_pair_with_refinement (p1_is_constant_size_without_actions: bool) (name1: string) (#nz1:_) (#k1:parser_kind nz1 WeakKindStrongPrefix) (#t1:Type) (#[@@@erasable] p1:parser k1 t1) (#[@@@erasable] inv1:slice_inv) (#[@@@erasable] l1:eloc) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#nz2:_) (#wk2: _) (#k2:parser_kind nz2 wk2) (#[@@@erasable] t2:refine _ f -> Type) (#[@@@erasable] p2:(x:refine _ f -> parser k2 (t2 x))) (#[@@@erasable] inv2:slice_inv) (#[@@@erasable] l2:eloc) (#allow_reading2:bool) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 allow_reading2)) : validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false
[]
EverParse3d.Actions.Base.validate_dep_pair_with_refinement
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p1_is_constant_size_without_actions: Prims.bool -> name1: Prims.string -> v1: EverParse3d.Actions.Base.validate_with_action_t p1 inv1 l1 true -> r1: EverParse3d.Actions.Base.leaf_reader p1 -> f: (_: t1 -> Prims.bool) -> v2: (x: EverParse3d.Prelude.refine t1 f -> EverParse3d.Actions.Base.validate_with_action_t (p2 x) inv2 l2 allow_reading2) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_dep_pair (EverParse3d.Prelude.parse_filter p1 f) p2) (EverParse3d.Actions.Base.conj_inv inv1 inv2) (EverParse3d.Actions.Base.eloc_union l1 l2) false
{ "end_col": 57, "end_line": 648, "start_col": 4, "start_line": 641 }
Prims.Tot
val read____UINT32 : leaf_reader parse____UINT32
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read____UINT32 : leaf_reader parse____UINT32 = lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL
val read____UINT32 : leaf_reader parse____UINT32 let read____UINT32:leaf_reader parse____UINT32 =
false
null
false
lift_reader _ LowParse.Low.BoundedInt.read_u32_le 4ul 4uL
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u32_kind", "FStar.UInt32.t", "LowParse.Spec.BoundedInt.parse_u32_le", "LowParse.Low.BoundedInt.read_u32_le", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT32", "EverParse3d.Prelude.___UINT32", "EverParse3d.Prelude.parse____UINT32" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read____UINT32 : leaf_reader parse____UINT32
[]
EverParse3d.Actions.Base.read____UINT32
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT32
{ "end_col": 59, "end_line": 1419, "start_col": 2, "start_line": 1419 }
Prims.Tot
val validate____UINT16BE : validator parse____UINT16BE
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate____UINT16BE : validator parse____UINT16BE = validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _)
val validate____UINT16BE : validator parse____UINT16BE let validate____UINT16BE:validator parse____UINT16BE =
false
null
false
validate_with_comment "Checking that we have enough space for a UINT16BE, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16BE 2uL () _ _)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT16BE", "EverParse3d.Prelude.___UINT16BE", "EverParse3d.Prelude.parse____UINT16BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate____UINT16BE : validator parse____UINT16BE
[]
EverParse3d.Actions.Base.validate____UINT16BE
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT16BE
{ "end_col": 73, "end_line": 1366, "start_col": 4, "start_line": 1364 }
Prims.Tot
val validate____UINT16 : validator parse____UINT16
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate____UINT16 : validator parse____UINT16 = validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _)
val validate____UINT16 : validator parse____UINT16 let validate____UINT16:validator parse____UINT16 =
false
null
false
validate_with_comment "Checking that we have enough space for a UINT16, i.e., 2 bytes" (validate_total_constant_size_no_read parse____UINT16 2uL () _ _)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT16", "EverParse3d.Prelude.___UINT16", "EverParse3d.Prelude.parse____UINT16", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate____UINT16 : validator parse____UINT16
[]
EverParse3d.Actions.Base.validate____UINT16
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT16
{ "end_col": 71, "end_line": 1402, "start_col": 4, "start_line": 1400 }
Prims.Tot
val validate____UINT8BE : validator parse____UINT8BE
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate____UINT8BE : validator parse____UINT8BE = validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _)
val validate____UINT8BE : validator parse____UINT8BE let validate____UINT8BE:validator parse____UINT8BE =
false
null
false
validate_with_comment "Checking that we have enough space for a UINT8BE, i.e., 1 byte" (validate_total_constant_size_no_read parse____UINT8BE 1uL () _ _)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT8BE", "EverParse3d.Prelude.___UINT8BE", "EverParse3d.Prelude.parse____UINT8BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate____UINT8BE : validator parse____UINT8BE
[]
EverParse3d.Actions.Base.validate____UINT8BE
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT8BE
{ "end_col": 72, "end_line": 1354, "start_col": 4, "start_line": 1352 }
Prims.Tot
val validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv l allow_reading) : Tot (validate_with_action_t (parse_nlist n p) inv l false)
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) #wk (#k:parser_kind true wk) #t (#p:parser k t) #inv #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l) else validate_nlist n v
val validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv l allow_reading) : Tot (validate_with_action_t (parse_nlist n p) inv l false) let validate_nlist_constant_size_without_actions (n_is_const: bool) (n: U32.t) #wk (#k: parser_kind true wk) #t (#p: parser k t) #inv #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv l false) =
false
null
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 l) else validate_nlist n v
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "Prims.op_AmpAmp", "Prims.op_Equality", "FStar.Pervasives.Native.option", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "LowParse.Spec.Base.parser_kind_metadata_some", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_metadata", "LowParse.Spec.Base.ParserKindMetadataTotal", "Prims.op_LessThan", "EverParse3d.Actions.Base.validate_drop", "EverParse3d.Kinds.kind_nlist", "EverParse3d.Prelude.nlist", "EverParse3d.Prelude.parse_nlist", "EverParse3d.Actions.Base.validate_nlist_total_constant_size", "EverParse3d.Actions.Base.validate_nlist", "EverParse3d.Kinds.WeakKindStrongPrefix" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv l false)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_nlist_constant_size_without_actions (n_is_const: bool) (n:U32.t) (#wk: _) (#k:parser_kind true wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#allow_reading:bool) (v: validate_with_action_t p inv l allow_reading) : Tot (validate_with_action_t (parse_nlist n p) inv l false)
[]
EverParse3d.Actions.Base.validate_nlist_constant_size_without_actions
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n_is_const: Prims.bool -> n: FStar.UInt32.t -> v: EverParse3d.Actions.Base.validate_with_action_t p inv l allow_reading -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv l false
{ "end_col": 22, "end_line": 1191, "start_col": 2, "start_line": 1182 }
Prims.Tot
val read____UINT32BE : leaf_reader parse____UINT32BE
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read____UINT32BE : leaf_reader parse____UINT32BE = lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL
val read____UINT32BE : leaf_reader parse____UINT32BE let read____UINT32BE:leaf_reader parse____UINT32BE =
false
null
false
lift_reader _ LowParse.Low.Int.read_u32 4ul 4uL
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u32_kind", "FStar.UInt32.t", "LowParse.Spec.Int.parse_u32", "LowParse.Low.Int.read_u32", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT32BE", "EverParse3d.Prelude.___UINT32BE", "EverParse3d.Prelude.parse____UINT32BE" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read____UINT32BE : leaf_reader parse____UINT32BE
[]
EverParse3d.Actions.Base.read____UINT32BE
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT32BE
{ "end_col": 49, "end_line": 1383, "start_col": 2, "start_line": 1383 }
Prims.Tot
val validate____UINT64 : validator parse____UINT64
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate____UINT64 : validator parse____UINT64 = validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _)
val validate____UINT64 : validator parse____UINT64 let validate____UINT64:validator parse____UINT64 =
false
null
false
validate_with_comment "Checking that we have enough space for a UINT64, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64 8uL () _ _)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT64", "EverParse3d.Prelude.___UINT64", "EverParse3d.Prelude.parse____UINT64", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate____UINT64 : validator parse____UINT64
[]
EverParse3d.Actions.Base.validate____UINT64
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT64
{ "end_col": 71, "end_line": 1426, "start_col": 4, "start_line": 1424 }
Prims.Tot
val read____UINT8 : leaf_reader parse____UINT8
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read____UINT8 : leaf_reader parse____UINT8 = lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
val read____UINT8 : leaf_reader parse____UINT8 let read____UINT8:leaf_reader parse____UINT8 =
false
null
false
lift_reader _ LowParse.Low.Int.read_u8 1ul 1uL
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Int.read_u8", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT8", "EverParse3d.Prelude.___UINT8", "EverParse3d.Prelude.parse____UINT8" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read____UINT8 : leaf_reader parse____UINT8
[]
EverParse3d.Actions.Base.read____UINT8
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT8
{ "end_col": 48, "end_line": 1347, "start_col": 2, "start_line": 1347 }
Prims.Tot
val validate_impos (_:unit) : validate_with_action_t (parse_impos ()) true_inv eloc_none true
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position
val validate_impos (_:unit) : validate_with_action_t (parse_impos ()) true_inv eloc_none true let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) =
false
null
false
fun _ _ _ _ start_position -> LPE.set_validator_error_pos LPE.validator_error_impossible start_position
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.unit", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_impossible", "FStar.UInt64.t", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.impos_kind", "Prims.l_False", "EverParse3d.Prelude.parse_impos", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos ()
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_impos (_:unit) : validate_with_action_t (parse_impos ()) true_inv eloc_none true
[]
EverParse3d.Actions.Base.validate_impos
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
_: Prims.unit -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_impos ()) EverParse3d.Actions.Base.true_inv EverParse3d.Actions.Base.eloc_none true
{ "end_col": 107, "end_line": 763, "start_col": 4, "start_line": 763 }
Prims.Tot
val read_unit : leaf_reader (parse_ret ())
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read_unit = fun input pos -> ()
val read_unit : leaf_reader (parse_ret ()) let read_unit =
false
null
false
fun input pos -> ()
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "Prims.unit" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read_unit : leaf_reader (parse_ret ())
[]
EverParse3d.Actions.Base.read_unit
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader (EverParse3d.Prelude.parse_ret ())
{ "end_col": 21, "end_line": 1439, "start_col": 2, "start_line": 1439 }
Prims.GTot
val validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (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
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (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 (I.footprint sl) h0 /\ 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
val validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt: app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool) : GTot Type0 let validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (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 =
false
null
false
let h0 = Ghost.reveal g0 in let h1 = Ghost.reveal g1 in let res = Seq.index (as_seq h bres) 0 in inv (I.footprint sl) h0 /\ (loc_not_unused_in h0) `loc_includes` (app_loc ctxt l) /\ (app_loc ctxt l) `loc_disjoint` (I.footprint sl) /\ (app_loc ctxt l) `loc_disjoint` (loc_buffer bres) /\ address_liveness_insensitive_locs `loc_includes` (app_loc ctxt l) /\ (B.loc_buffer bres) `B.loc_disjoint` (I.footprint sl) /\ I.live sl h0 /\ I.live sl h /\ live h0 ctxt /\ live h ctxt /\ live h1 bres /\ (let s = I.get_remaining sl h0 in let s' = I.get_remaining sl h in Seq.length s' <= Seq.length s /\ s' `Seq.equal` (Seq.slice s (Seq.length s - Seq.length s') (Seq.length s))) /\ modifies loc_none h0 h1 /\ (if LPE.is_error res then stop == true /\ U64.v (LPE.get_validator_error_pos res) == Seq.length (I.get_read sl h) /\ (LPE.get_validator_error_kind res <> LPE.get_validator_error_kind LPE.validator_error_action_failed ==> ~(valid (LPLL.parse_list p) h0 sl)) else U64.v res == Seq.length (I.get_read sl h) /\ (valid (LPLL.parse_list p) h0 sl <==> valid (LPLL.parse_list p) h sl) /\ (stop == true ==> (valid (LPLL.parse_list p) h sl /\ Seq.length (I.get_remaining sl h) == 0))) /\ modifies (((app_loc ctxt l) `loc_union` (loc_buffer bres)) `loc_union` (I.perm_footprint sl)) h1 h
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "sometrivial" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "FStar.Ghost.erased", "FStar.Monotonic.HyperStack.mem", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.input_buffer_t", "LowStar.Buffer.pointer", "FStar.UInt64.t", "Prims.bool", "Prims.l_and", "EverParse3d.InputStream.Base.footprint", "EverParse3d.InputStream.All.inst", "LowStar.Monotonic.Buffer.loc_includes", "LowStar.Monotonic.Buffer.loc_not_unused_in", "FStar.Ghost.reveal", "LowStar.Monotonic.Buffer.loc", "EverParse3d.Actions.Base.app_loc", "LowStar.Monotonic.Buffer.loc_disjoint", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "LowStar.Monotonic.Buffer.address_liveness_insensitive_locs", "EverParse3d.InputStream.Base.live", "LowStar.Monotonic.Buffer.live", "FStar.UInt8.t", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "Prims.op_Subtraction", "FStar.Seq.Base.seq", "EverParse3d.InputStream.Base.get_remaining", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "EverParse3d.ErrorCode.is_error", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.op_GreaterThanOrEqual", "FStar.UInt64.v", "EverParse3d.ErrorCode.get_validator_error_pos", "EverParse3d.InputStream.Base.get_read", "Prims.l_imp", "Prims.op_disEquality", "Prims.op_LessThan", "EverParse3d.ErrorCode.get_validator_error_kind", "EverParse3d.ErrorCode.validator_error_action_failed", "Prims.l_not", "EverParse3d.Actions.Base.valid", "LowParse.Spec.List.parse_list_kind", "Prims.list", "LowParse.Spec.List.parse_list", "Prims.l_iff", "Prims.logical", "LowStar.Monotonic.Buffer.loc_union", "EverParse3d.InputStream.Base.perm_footprint", "FStar.Seq.Base.index", "LowStar.Monotonic.Buffer.as_seq" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (l: eloc) (g0 g1: Ghost.erased HS.mem) (ctxt:app_ctxt) (sl: input_buffer_t) (bres: pointer U64.t) (h: HS.mem) (stop: bool)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_list_inv (#k: LPL.parser_kind) (#t: Type) (p: LPL.parser k t) (inv: slice_inv) (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
[]
EverParse3d.Actions.Base.validate_list_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p: LowParse.Spec.Base.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> l: EverParse3d.Actions.Base.eloc -> g0: FStar.Ghost.erased FStar.Monotonic.HyperStack.mem -> g1: FStar.Ghost.erased FStar.Monotonic.HyperStack.mem -> ctxt: EverParse3d.Actions.Base.app_ctxt -> sl: EverParse3d.Actions.Base.input_buffer_t -> bres: LowStar.Buffer.pointer FStar.UInt64.t -> h: FStar.Monotonic.HyperStack.mem -> stop: Prims.bool -> Prims.GTot Type0
{ "end_col": 92, "end_line": 823, "start_col": 1, "start_line": 789 }
Prims.Tot
val read_impos : leaf_reader (parse_impos())
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read_impos : leaf_reader (parse_impos()) = fun sl pos -> false_elim ()
val read_impos : leaf_reader (parse_impos()) let read_impos:leaf_reader (parse_impos ()) =
false
null
false
fun sl pos -> false_elim ()
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "FStar.Pervasives.false_elim", "Prims.l_False", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.impos_kind", "EverParse3d.Prelude.parse_impos" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read_impos : leaf_reader (parse_impos())
[]
EverParse3d.Actions.Base.read_impos
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader (EverParse3d.Prelude.parse_impos ())
{ "end_col": 19, "end_line": 1313, "start_col": 4, "start_line": 1312 }
Prims.Tot
val validate____UINT64BE : validator parse____UINT64BE
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate____UINT64BE : validator parse____UINT64BE = validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _)
val validate____UINT64BE : validator parse____UINT64BE let validate____UINT64BE:validator parse____UINT64BE =
false
null
false
validate_with_comment "Checking that we have enough space for a UINT64BE, i.e., 8 bytes" (validate_total_constant_size_no_read parse____UINT64BE 8uL () _ _)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.validate_with_comment", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind____UINT64BE", "EverParse3d.Prelude.___UINT64BE", "EverParse3d.Prelude.parse____UINT64BE", "EverParse3d.Actions.Base.true_inv", "EverParse3d.Actions.Base.eloc_none", "EverParse3d.Actions.Base.validate_total_constant_size_no_read", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.validator" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate____UINT64BE : validator parse____UINT64BE
[]
EverParse3d.Actions.Base.validate____UINT64BE
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.validator EverParse3d.Prelude.parse____UINT64BE
{ "end_col": 73, "end_line": 1390, "start_col": 4, "start_line": 1388 }
Prims.Tot
val read____UINT64 : leaf_reader parse____UINT64
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read____UINT64 : leaf_reader parse____UINT64 = lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL
val read____UINT64 : leaf_reader parse____UINT64 let read____UINT64:leaf_reader parse____UINT64 =
false
null
false
lift_reader _ LowParse.Low.Int.read_u64_le 8ul 8uL
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.lift_reader", "LowParse.Spec.Int.parse_u64_kind", "FStar.UInt64.t", "LowParse.Spec.Int.parse_u64_le", "LowParse.Low.Int.read_u64_le", "FStar.UInt32.__uint_to_t", "FStar.UInt64.__uint_to_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Kinds.kind____UINT64", "EverParse3d.Prelude.___UINT64", "EverParse3d.Prelude.parse____UINT64" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read____UINT64 : leaf_reader parse____UINT64
[]
EverParse3d.Actions.Base.read____UINT64
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.leaf_reader EverParse3d.Prelude.parse____UINT64
{ "end_col": 52, "end_line": 1431, "start_col": 2, "start_line": 1431 }
Prims.Tot
val action_deref (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#a:_) (x:bpointer a) : action p (ptr_inv x) eloc_none false a
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let action_deref #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a) : action p (ptr_inv x) loc_none false a = fun _ _ _ _ -> !*x
val action_deref (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#a:_) (x:bpointer a) : action p (ptr_inv x) eloc_none false a let action_deref #nz #wk (#k: parser_kind nz wk) (#t: Type) (#p: parser k t) (#a: _) (x: B.pointer a) : action p (ptr_inv x) loc_none false a =
false
null
false
fun _ _ _ _ -> !*x
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "LowStar.Buffer.pointer", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.ErrorCode.pos_t", "LowStar.BufferOps.op_Bang_Star", "LowStar.Buffer.trivial_preorder", "EverParse3d.Actions.Base.action", "EverParse3d.Actions.Base.ptr_inv", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_none", "EverParse3d.Actions.Base.eloc_none" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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 #t #p v r terminator = 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 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:Type) (x:a) : action p true_inv eloc_none false a = fun _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: (a -> action p invg lg bg b)) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt input pos posf noextract inline_for_extraction let action_seq #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in let _ = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt input pos posf noextract inline_for_extraction let action_ite #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a = fun ctxt input pos posf -> if guard then then_ () ctxt input pos posf else else_ () ctxt input pos posf noextract inline_for_extraction let action_abort #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) : action p true_inv eloc_none false bool = fun _ _ _ _ -> false noextract inline_for_extraction let action_field_pos_64 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (u:unit) : action p true_inv eloc_none false U64.t = 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) *) noextract inline_for_extraction let action_deref #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val action_deref (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#a:_) (x:bpointer a) : action p (ptr_inv x) eloc_none false a
[]
EverParse3d.Actions.Base.action_deref
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.Actions.Base.bpointer a -> EverParse3d.Actions.Base.action p (EverParse3d.Actions.Base.ptr_inv x) EverParse3d.Actions.Base.eloc_none false a
{ "end_col": 23, "end_line": 1675, "start_col": 5, "start_line": 1675 }
Prims.Tot
val read_filter (#nz:_) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#[@@@erasable] p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f)
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) = fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos
val read_filter (#nz:_) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#[@@@erasable] p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) let read_filter #nz (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f) =
false
null
false
fun input pos -> let h = HST.get () in assert (parse_filter p f == LPC.parse_filter #k #t p f); assert_norm (P.refine t f == LPC.parse_filter_refine f); LPC.parse_filter_eq p f (I.get_remaining input h); p32 input pos
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.ErrorCode.pos_t", "Prims.unit", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining", "EverParse3d.Prelude.refine", "FStar.Pervasives.assert_norm", "Prims.eq2", "LowParse.Spec.Combinators.parse_filter_refine", "Prims._assert", "LowParse.Spec.Base.parser", "LowParse.Spec.Combinators.parse_filter_kind", "EverParse3d.Prelude.parse_filter", "LowParse.Spec.Combinators.parse_filter", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Kinds.filter_kind" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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))
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val read_filter (#nz:_) (#k: parser_kind nz WeakKindStrongPrefix) (#t: Type) (#[@@@erasable] p: parser k t) (p32: leaf_reader p) (f: (t -> bool)) : leaf_reader (parse_filter p f)
[]
EverParse3d.Actions.Base.read_filter
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
p32: EverParse3d.Actions.Base.leaf_reader p -> f: (_: t -> Prims.bool) -> EverParse3d.Actions.Base.leaf_reader (EverParse3d.Prelude.parse_filter p f)
{ "end_col": 21, "end_line": 1307, "start_col": 6, "start_line": 1302 }
Prims.Tot
val action_assignment (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#a:_) (x:bpointer a) (v:a) : action p (ptr_inv x) (ptr_loc x) false unit
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let action_assignment #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a) (v:a) : action p (ptr_inv x) (ptr_loc x) false unit = fun _ _ _ _ -> x *= v
val action_assignment (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#a:_) (x:bpointer a) (v:a) : action p (ptr_inv x) (ptr_loc x) false unit let action_assignment #nz #wk (#k: parser_kind nz wk) (#t: Type) (#p: parser k t) (#a: _) (x: B.pointer a) (v: a) : action p (ptr_inv x) (ptr_loc x) false unit =
false
null
false
fun _ _ _ _ -> x *= v
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "LowStar.Buffer.pointer", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.ErrorCode.pos_t", "LowStar.BufferOps.op_Star_Equals", "LowStar.Buffer.trivial_preorder", "Prims.unit", "EverParse3d.Actions.Base.action", "EverParse3d.Actions.Base.ptr_inv", "EverParse3d.Actions.Base.ptr_loc" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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 #t #p v r terminator = 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 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:Type) (x:a) : action p true_inv eloc_none false a = fun _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: (a -> action p invg lg bg b)) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt input pos posf noextract inline_for_extraction let action_seq #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in let _ = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt input pos posf noextract inline_for_extraction let action_ite #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a = fun ctxt input pos posf -> if guard then then_ () ctxt input pos posf else else_ () ctxt input pos posf noextract inline_for_extraction let action_abort #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) : action p true_inv eloc_none false bool = fun _ _ _ _ -> false noextract inline_for_extraction let action_field_pos_64 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (u:unit) : action p true_inv eloc_none false U64.t = 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) *) noextract inline_for_extraction let action_deref #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a) : action p (ptr_inv x) loc_none false a = fun _ _ _ _ -> !*x noextract inline_for_extraction let action_assignment #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a) (v:a)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val action_assignment (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#a:_) (x:bpointer a) (v:a) : action p (ptr_inv x) (ptr_loc x) false unit
[]
EverParse3d.Actions.Base.action_assignment
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.Actions.Base.bpointer a -> v: a -> EverParse3d.Actions.Base.action p (EverParse3d.Actions.Base.ptr_inv x) (EverParse3d.Actions.Base.ptr_loc x) false Prims.unit
{ "end_col": 26, "end_line": 1683, "start_col": 5, "start_line": 1683 }
Prims.Tot
val action_weaken (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#b:_) (#a:_) (act:action p inv l b a) (#[@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) (#l':eloc{l' `eloc_includes` l}) : action p inv' l' b a
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let action_weaken #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#inv:slice_inv) (#l:eloc) (#b:_) (#a:_) (act:action p inv l b a) (#inv':slice_inv{inv' `inv_implies` inv}) (#l':eloc{l' `eloc_includes` l}) : action p inv' l' b a = act
val action_weaken (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#b:_) (#a:_) (act:action p inv l b a) (#[@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) (#l':eloc{l' `eloc_includes` l}) : action p inv' l' b a let action_weaken #nz #wk (#k: parser_kind nz wk) (#t: Type) (#p: parser k t) (#inv: slice_inv) (#l: eloc) (#b: _) (#a: _) (act: action p inv l b a) (#inv': slice_inv{inv' `inv_implies` inv}) (#l': eloc{l' `eloc_includes` l}) : action p inv' l' b a =
false
null
false
act
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.action", "EverParse3d.Actions.Base.inv_implies", "EverParse3d.Actions.Base.eloc_includes" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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 #t #p v r terminator = 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 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:Type) (x:a) : action p true_inv eloc_none false a = fun _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: (a -> action p invg lg bg b)) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt input pos posf noextract inline_for_extraction let action_seq #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in let _ = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt input pos posf noextract inline_for_extraction let action_ite #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a = fun ctxt input pos posf -> if guard then then_ () ctxt input pos posf else else_ () ctxt input pos posf noextract inline_for_extraction let action_abort #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) : action p true_inv eloc_none false bool = fun _ _ _ _ -> false noextract inline_for_extraction let action_field_pos_64 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (u:unit) : action p true_inv eloc_none false U64.t = 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) *) noextract inline_for_extraction let action_deref #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a) : action p (ptr_inv x) loc_none false a = fun _ _ _ _ -> !*x noextract inline_for_extraction let action_assignment #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:_) (x:B.pointer a) (v:a) : action p (ptr_inv x) (ptr_loc x) false unit = fun _ _ _ _ -> x *= v (* FIXME: This is now unsound. noextract inline_for_extraction let action_read_value #nz (#k:parser_kind nz) (#t:Type) (#p:parser k t) (r:leaf_reader p) : action p true_inv eloc_none true t = fun input startPosition endPosition -> r input (LPL.uint64_to_uint32 startPosition) *) noextract inline_for_extraction let action_weaken #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#inv:slice_inv) (#l:eloc) (#b:_) (#a:_) (act:action p inv l b a) (#inv':slice_inv{inv' `inv_implies` inv}) (#l':eloc{l' `eloc_includes` l})
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val action_weaken (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (#b:_) (#a:_) (act:action p inv l b a) (#[@@@erasable] inv':slice_inv{inv' `inv_implies` inv}) (#l':eloc{l' `eloc_includes` l}) : action p inv' l' b a
[]
EverParse3d.Actions.Base.action_weaken
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
act: EverParse3d.Actions.Base.action p inv l b a -> EverParse3d.Actions.Base.action p inv' l' b a
{ "end_col": 8, "end_line": 1703, "start_col": 5, "start_line": 1703 }
Prims.Tot
val validate_weaken (#nz #wk: _) (#k: parser_kind nz wk) (#t: _) (#p: parser k t) (#inv #l #ar: _) (v: validate_with_action_t p inv l ar) (#nz' #wk': _) (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv l ar)
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_weaken #nz #wk (#k:parser_kind nz wk) #t (#p:parser k t) #inv #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv l ar) = fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position
val validate_weaken (#nz #wk: _) (#k: parser_kind nz wk) (#t: _) (#p: parser k t) (#inv #l #ar: _) (v: validate_with_action_t p inv l ar) (#nz' #wk': _) (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv l ar) let validate_weaken #nz #wk (#k: parser_kind nz wk) #t (#p: parser k t) #inv #l #ar (v: validate_with_action_t p inv l ar) #nz' #wk' (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv l ar) =
false
null
false
fun ctxt error_handler_fn input input_length start_position -> v ctxt error_handler_fn input input_length start_position
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Prelude.is_weaker_than", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "EverParse3d.Prelude.parse_weaken" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k})
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_weaken (#nz #wk: _) (#k: parser_kind nz wk) (#t: _) (#p: parser k t) (#inv #l #ar: _) (v: validate_with_action_t p inv l ar) (#nz' #wk': _) (k': parser_kind nz' wk' {k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv l ar)
[]
EverParse3d.Actions.Base.validate_weaken
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
v: EverParse3d.Actions.Base.validate_with_action_t p inv l ar -> k': EverParse3d.Kinds.parser_kind nz' wk' {EverParse3d.Prelude.is_weaker_than k' k} -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_weaken p k') inv l ar
{ "end_col": 61, "end_line": 739, "start_col": 4, "start_line": 738 }
Prims.Tot
val action_seq (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action p invf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b)
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let action_seq #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in let _ = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt input pos posf
val action_seq (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action p invf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) let action_seq #nz #wk (#k: parser_kind nz wk) (#t: Type) (#p: parser k t) (#invf: slice_inv) (#lf: eloc) #bf (#a: Type) (f: action p invf lf bf a) (#invg: slice_inv) (#lg: eloc) #bg (#b: Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) =
false
null
false
fun ctxt input pos posf -> let h0 = HST.get () in let _ = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt input pos posf
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "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.ErrorCode.pos_t", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.eloc_union", "Prims.op_BarBar" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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 #t #p v r terminator = 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 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:Type) (x:a) : action p true_inv eloc_none false a = fun _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: (a -> action p invg lg bg b)) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt input pos posf noextract inline_for_extraction let action_seq #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: action p invg lg bg b)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val action_seq (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] lf:eloc) (#bf:_) (#a:Type) (f: action p invf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] lg:eloc) (#bg:_) (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b)
[]
EverParse3d.Actions.Base.action_seq
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
f: EverParse3d.Actions.Base.action p invf lf bf a -> g: EverParse3d.Actions.Base.action p invg lg bg b -> EverParse3d.Actions.Base.action p (EverParse3d.Actions.Base.conj_inv invf invg) (EverParse3d.Actions.Base.eloc_union lf lg) (bf || bg) b
{ "end_col": 25, "end_line": 1627, "start_col": 4, "start_line": 1622 }
Prims.Tot
val validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#l: eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv l false)
[ { "abbrev": true, "full_module": "LowParse.Low.Base", "short_module": "LPL" }, { "abbrev": true, "full_module": "LowParse.Spec.Base", "short_module": "LP" }, { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_drop_true (#k:LP.parser_kind) (#t:Type) (#p:LP.parser k t) (#inv:slice_inv) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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
val validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#l: eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv l false) let validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#l: eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv l false) =
false
null
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
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t'", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "FStar.UInt64.t", "Prims.unit", "EverParse3d.InputStream.Base.skip_if_success" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_drop_true (#k: LP.parser_kind) (#t: Type) (#p: LP.parser k t) (#inv: slice_inv) (#l: eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv l false)
[]
EverParse3d.Actions.Base.validate_drop_true
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
v: EverParse3d.Actions.Base.validate_with_action_t' p inv l true -> EverParse3d.Actions.Base.validate_with_action_t' p inv l false
{ "end_col": 5, "end_line": 275, "start_col": 2, "start_line": 271 }
Prims.Tot
val validate_list (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #l #ar: _) (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv l false)
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_list (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv l false) = fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position
val validate_list (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #l #ar: _) (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv l false) let validate_list (#k: LP.parser_kind) #t (#p: LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv l false) =
false
null
false
fun ctxt error_handler_fn input input_length start_position -> validate_list' v ctxt error_handler_fn input input_length start_position
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "Prims.bool", "EverParse3d.Actions.Base.validate_with_action_t'", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.Actions.Base.validate_list'", "FStar.UInt64.t", "LowParse.Spec.List.parse_list_kind", "Prims.list", "LowParse.Spec.List.parse_list" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_list (#k: LP.parser_kind) (#t: _) (#p: LP.parser k t) (#inv #l #ar: _) (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv l false)
[]
EverParse3d.Actions.Base.validate_list
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
v: EverParse3d.Actions.Base.validate_with_action_t' p inv l ar -> EverParse3d.Actions.Base.validate_with_action_t' (LowParse.Spec.List.parse_list p) inv l false
{ "end_col": 74, "end_line": 932, "start_col": 2, "start_line": 931 }
Prims.Tot
val bpointer (a: Type0) : Tot Type0
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let bpointer a = B.pointer a
val bpointer (a: Type0) : Tot Type0 let bpointer a =
false
null
false
B.pointer a
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowStar.Buffer.pointer" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = ()
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val bpointer (a: Type0) : Tot Type0
[]
EverParse3d.Actions.Base.bpointer
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
a: Type0 -> Type0
{ "end_col": 28, "end_line": 43, "start_col": 17, "start_line": 43 }
Prims.Tot
val eloc_none : eloc
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let eloc_none : eloc = B.loc_none
val eloc_none : eloc let eloc_none:eloc =
false
null
false
B.loc_none
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_none", "EverParse3d.Actions.Base.eloc" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl h let eloc = (l: FStar.Ghost.erased B.loc { B.address_liveness_insensitive_locs `B.loc_includes` l })
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val eloc_none : eloc
[]
EverParse3d.Actions.Base.eloc_none
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
EverParse3d.Actions.Base.eloc
{ "end_col": 33, "end_line": 32, "start_col": 23, "start_line": 32 }
Prims.Tot
val action_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] lf:eloc) (guard:bool) (#bf:_) (#a:Type) (then_: squash guard -> action p invf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] lg:eloc) (#bg:_) (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let action_ite #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a = fun ctxt input pos posf -> if guard then then_ () ctxt input pos posf else else_ () ctxt input pos posf
val action_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] lf:eloc) (guard:bool) (#bf:_) (#a:Type) (then_: squash guard -> action p invf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] lg:eloc) (#bg:_) (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a let action_ite #nz #wk (#k: parser_kind nz wk) (#t: Type) (#p: parser k t) (#invf: slice_inv) (#lf: eloc) (guard: bool) #bf (#a: Type) (then_: (squash guard -> action p invf lf bf a)) (#invg: slice_inv) (#lg: eloc) #bg (else_: (squash (not guard) -> action p invg lg bg a)) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a =
false
null
false
fun ctxt input pos posf -> if guard then then_ () ctxt input pos posf else else_ () ctxt input pos posf
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.bool", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "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.ErrorCode.pos_t", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.eloc_union", "Prims.op_BarBar" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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 #t #p v r terminator = 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 #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#a:Type) (x:a) : action p true_inv eloc_none false a = fun _ _ _ _ -> x noextract inline_for_extraction let action_bind (name: string) #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: (a -> action p invg lg bg b)) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in [@(rename_let ("" ^ name))] let x = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g x ctxt input pos posf noextract inline_for_extraction let action_seq #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) #bf (#a:Type) (f: action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (#b:Type) (g: action p invg lg bg b) : Tot (action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) b) = fun ctxt input pos posf -> let h0 = HST.get () in let _ = f ctxt input pos posf in let h1 = HST.get () in modifies_address_liveness_insensitive_unused_in h0 h1; g ctxt input pos posf noextract inline_for_extraction let action_ite #nz #wk (#k:parser_kind nz wk) (#t:Type) (#p:parser k t) (#invf:slice_inv) (#lf:eloc) (guard:bool) #bf (#a:Type) (then_: squash guard -> action p invf lf bf a) (#invg:slice_inv) (#lg:eloc) #bg (else_: squash (not guard) -> action p invg lg bg a)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val action_ite (#nz:_) (#wk: _) (#k:parser_kind nz wk) (#[@@@erasable] t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] invf:slice_inv) (#[@@@erasable] lf:eloc) (guard:bool) (#bf:_) (#a:Type) (then_: squash guard -> action p invf lf bf a) (#[@@@erasable] invg:slice_inv) (#[@@@erasable] lg:eloc) (#bg:_) (else_: squash (not guard) -> action p invg lg bg a) : action p (conj_inv invf invg) (eloc_union lf lg) (bf || bg) a
[]
EverParse3d.Actions.Base.action_ite
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
guard: Prims.bool -> then_: (_: Prims.squash guard -> EverParse3d.Actions.Base.action p invf lf bf a) -> else_: (_: Prims.squash (Prims.op_Negation guard) -> EverParse3d.Actions.Base.action p invg lg bg a) -> EverParse3d.Actions.Base.action p (EverParse3d.Actions.Base.conj_inv invf invg) (EverParse3d.Actions.Base.eloc_union lf lg) (bf || bg) a
{ "end_col": 39, "end_line": 1642, "start_col": 4, "start_line": 1639 }
Prims.Tot
[ { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let app_ctxt = B.pointer U8.t
let app_ctxt =
false
null
false
B.pointer U8.t
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowStar.Buffer.pointer", "FStar.UInt8.t" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val app_ctxt : Type0
[]
EverParse3d.Actions.Base.app_ctxt
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type0
{ "end_col": 29, "end_line": 48, "start_col": 15, "start_line": 48 }
Prims.Tot
val conj_inv (i0 i1: slice_inv) : Tot slice_inv
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl h
val conj_inv (i0 i1: slice_inv) : Tot slice_inv let conj_inv (i0 i1: slice_inv) : slice_inv =
false
null
false
fun sl h -> i0 sl h /\ i1 sl h
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.slice_inv", "LowStar.Monotonic.Buffer.loc", "FStar.Monotonic.HyperStack.mem", "Prims.l_and" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val conj_inv (i0 i1: slice_inv) : Tot slice_inv
[]
EverParse3d.Actions.Base.conj_inv
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
i0: EverParse3d.Actions.Base.slice_inv -> i1: EverParse3d.Actions.Base.slice_inv -> EverParse3d.Actions.Base.slice_inv
{ "end_col": 75, "end_line": 29, "start_col": 45, "start_line": 29 }
Prims.Tot
[ { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let input_buffer_t = EverParse3d.InputStream.All.t
let input_buffer_t =
false
null
false
EverParse3d.InputStream.All.t
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.InputStream.All.t" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val input_buffer_t : Type0
[]
EverParse3d.Actions.Base.input_buffer_t
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
Type0
{ "end_col": 50, "end_line": 53, "start_col": 21, "start_line": 53 }
Prims.Pure
val validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv l: _) : Pure (validate_with_action_t (parse_nlist n p) inv 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))
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_nlist_constant_size_mod_ko (n:U32.t) (#wk: _) (#k:parser_kind true wk) #t (p:parser k t) inv l : Pure (validate_with_action_t (parse_nlist n p) inv 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 )
val validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv l: _) : Pure (validate_with_action_t (parse_nlist n p) inv l true) (requires (let open LP in k.parser_kind_subkind == Some ParserStrong /\ k.parser_kind_high == Some k.parser_kind_low /\ U32.v n % k.LP.parser_kind_low <> 0)) (ensures (fun _ -> True)) let validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) #t (p: parser k t) inv l : Pure (validate_with_action_t (parse_nlist n p) inv 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)) =
false
null
false
(fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos = start_position in let h = FStar.HyperStack.ST.get () in [@@ inline_let ]let f () : Lemma (requires (Some? (LP.parse (parse_nlist n p) (I.get_remaining input h)))) (ensures False) = let sq = I.get_remaining input h in let sq' = Seq.slice sq 0 (U32.v n) in LowParse.Spec.List.list_length_constant_size_parser_correct p sq'; let Some (l, _) = LP.parse (parse_nlist n p) sq in assert (U32.v n == (FStar.List.Tot.length l) `Prims.op_Multiply` k.LP.parser_kind_low); FStar.Math.Lemmas.cancel_mul_mod (FStar.List.Tot.length l) k.LP.parser_kind_low; assert (U32.v n % k.LP.parser_kind_low == 0) in [@@ inline_let ]let _ = Classical.move_requires f () in LPE.set_validator_error_pos LPE.validator_error_list_size_not_multiple pos)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[]
[ "FStar.UInt32.t", "EverParse3d.Kinds.weak_kind", "EverParse3d.Kinds.parser_kind", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_list_size_not_multiple", "Prims.unit", "FStar.Classical.move_requires", "Prims.b2t", "FStar.Pervasives.Native.uu___is_Some", "FStar.Pervasives.Native.tuple2", "EverParse3d.Prelude.nlist", "LowParse.Spec.Base.consumed_length", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Base.parse", "EverParse3d.Prelude.parse_nlist", "Prims.l_False", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.op_Modulus", "FStar.UInt32.v", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low", "FStar.Math.Lemmas.cancel_mul_mod", "FStar.List.Tot.Base.length", "Prims.op_Multiply", "FStar.Pervasives.Native.option", "LowParse.Spec.List.list_length_constant_size_parser_correct", "FStar.Seq.Base.seq", "FStar.UInt8.t", "FStar.Seq.Base.slice", "FStar.UInt64.t", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Kinds.kind_nlist", "Prims.l_and", "LowParse.Spec.Base.parser_subkind", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind", "FStar.Pervasives.Native.Some", "LowParse.Spec.Base.ParserStrong", "Prims.nat", "LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high", "Prims.op_disEquality", "Prims.l_True" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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))
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_nlist_constant_size_mod_ko (n: U32.t) (#wk: _) (#k: parser_kind true wk) (#t: _) (p: parser k t) (inv l: _) : Pure (validate_with_action_t (parse_nlist n p) inv 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))
[]
EverParse3d.Actions.Base.validate_nlist_constant_size_mod_ko
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
n: FStar.UInt32.t -> p: EverParse3d.Prelude.parser k t -> inv: EverParse3d.Actions.Base.slice_inv -> l: EverParse3d.Actions.Base.eloc -> Prims.Pure (EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_nlist n p) inv l true)
{ "end_col": 3, "end_line": 1124, "start_col": 2, "start_line": 1106 }
FStar.HyperStack.ST.Stack
val validate_list_up_to_body (#[FStar.Tactics.Typeclasses.tcresolve ()] _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))
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_list_up_to_body (# [FStar.Tactics.Typeclasses.tcresolve ()] _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
val validate_list_up_to_body (#[FStar.Tactics.Typeclasses.tcresolve ()] _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 (#[FStar.Tactics.Typeclasses.tcresolve ()] _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)) =
true
null
false
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
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[]
[ "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" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_list_up_to_body (#[FStar.Tactics.Typeclasses.tcresolve ()] _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))
[]
EverParse3d.Actions.Base.validate_list_up_to_body
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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
{ "end_col": 5, "end_line": 1542, "start_col": 1, "start_line": 1530 }
Prims.Tot
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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv eloc_none false)
[ { "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": "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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
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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv 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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv eloc_none false) =
false
null
false
fun ctxt error_handler_fn sl sl_len pos -> let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in fresh_frame_modifies h0 h1; let bres = B.alloca pos 1ul in let h2 = HST.get () in I.live_not_unused_in sl h0; C.Loops.do_while (validate_list_up_to_inv p terminator prf ctxt sl h2 bres) (fun _ -> validate_list_up_to_body terminator prf v r ctxt error_handler_fn sl sl_len h2 bres); let result = B.index bres 0ul in HST.pop_frame (); result
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "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.eloc_none" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (#b:bool) #inva (#la:eloc) (a: t -> action p inva la b bool) : Tot (validate_with_action_t #nz p (conj_inv inv inva) (eloc_union l la) false) = 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 input 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 #l #ar (v:validate_with_action_t p inv l ar) #nz' #wk' (k':parser_kind nz' wk'{k' `is_weaker_than` k}) : Tot (validate_with_action_t (parse_weaken p k') inv 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_left p k') inv l ar = 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:_) (#l:_) #ar (v:validate_with_action_t p inv l ar) (#nz':_) #wk' (k':parser_kind nz' wk') : validate_with_action_t (parse_weaken_right p k') inv l ar = validate_weaken v (glb k k') inline_for_extraction noextract let validate_impos () : Tot (validate_with_action_t (parse_impos ()) true_inv eloc_none true) = 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) (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 (I.footprint sl) h0 /\ 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 l g0 g1 ctxt sl bres h false)) (ensures (fun h res h' -> validate_list_inv p inv l g0 g1 ctxt sl bres h false /\ validate_list_inv p inv 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' (# [FStar.Tactics.Typeclasses.tcresolve ()] _extra_t : I.extra_t #input_buffer_t ) (#k:LP.parser_kind) #t (#p:LP.parser k t) #inv #l #ar (v: validate_with_action_t' p inv 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 (I.footprint sl) h /\ 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 (I.footprint sl) 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 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.List.parse_list p) inv 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 #l #ar (v: validate_with_action_t' p inv l ar { k.LP.parser_kind_subkind == Some LP.ParserConsumesAll }) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t' p inv l ar) : Tot (validate_with_action_t' (LowParse.Spec.FLData.parse_fldata p (U32.v n)) inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 l : Tot (validate_with_action_t' p inv 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 l : Tot (validate_with_action_t p inv l true) = validate_total_constant_size_no_read' p sz u inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 l ctxt error_handler_fn input start_position else validate_nlist_constant_size_mod_ko n p inv 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 l : Pure (validate_with_action_t (parse_nlist n p) inv 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 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 l else validate_nlist_total_constant_size' n p inv 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 #l #ar (v: validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_nlist n p) inv 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 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_at_most n p) inv 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:_) (#l:_) (#ar:_) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t (parse_t_exact n p) inv 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 #l #ar (v:validate_with_action_t p inv l ar) : validate_with_action_t p inv 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 (#l:eloc) #ar (inv':slice_inv{inv' `inv_implies` inv}) (l':eloc{l' `eloc_includes` l}) (v:validate_with_action_t p inv l ar) : Tot (validate_with_action_t p inv' 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 (# [FStar.Tactics.Typeclasses.tcresolve ()] _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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv eloc_none false)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
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) : Tot (validate_with_action_t #true #WeakKindStrongPrefix (LUT.parse_list_up_to (cond_string_up_to terminator) p prf) true_inv eloc_none false)
[]
EverParse3d.Actions.Base.validate_list_up_to
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
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.eloc_none false
{ "end_col": 8, "end_line": 1570, "start_col": 2, "start_line": 1556 }
Prims.Tot
val ptr_loc (#a: _) (x: bpointer a) : Tot eloc
[ { "abbrev": true, "full_module": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let ptr_loc #a (x:B.pointer a) : Tot eloc = B.loc_buffer x
val ptr_loc (#a: _) (x: bpointer a) : Tot eloc let ptr_loc #a (x: B.pointer a) : Tot eloc =
false
null
false
B.loc_buffer x
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "LowStar.Buffer.pointer", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_buffer", "LowStar.Buffer.trivial_preorder", "EverParse3d.Actions.Base.eloc" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let eloc_includes_refl l = ()
false
false
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val ptr_loc (#a: _) (x: bpointer a) : Tot eloc
[]
EverParse3d.Actions.Base.ptr_loc
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.Actions.Base.bpointer a -> EverParse3d.Actions.Base.eloc
{ "end_col": 58, "end_line": 44, "start_col": 44, "start_line": 44 }
Prims.Tot
val app_loc (x: app_ctxt) (l: eloc) : eloc
[ { "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.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l
val app_loc (x: app_ctxt) (l: eloc) : eloc let app_loc (x: app_ctxt) (l: eloc) : eloc =
false
null
false
(B.loc_buffer x) `loc_union` l
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.eloc", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.loc", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "FStar.UInt8.t", "LowStar.Buffer.trivial_preorder", "FStar.Ghost.reveal" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x
false
true
EverParse3d.Actions.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 2, "max_fuel": 0, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [ "smt.qi.eager_threshold=10" ], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val app_loc (x: app_ctxt) (l: eloc) : eloc
[]
EverParse3d.Actions.Base.app_loc
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
x: EverParse3d.Actions.Base.app_ctxt -> l: EverParse3d.Actions.Base.eloc -> EverParse3d.Actions.Base.eloc
{ "end_col": 71, "end_line": 49, "start_col": 43, "start_line": 49 }
Prims.Tot
val validate_filter_with_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] la:eloc) (a: t -> action (p `parse_filter` f) inva la b bool) : validate_with_action_t #nz (p `parse_filter` f) (conj_inv inv inva) (eloc_union l la) false
[ { "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": "EverParse3d.Prelude", "short_module": "P" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": false, "full_module": "FStar.Tactics.Typeclasses", "short_module": null }, { "abbrev": true, "full_module": "EverParse3d.ErrorCode", "short_module": "LPE" }, { "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": "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 } ]
false
let validate_filter_with_action (name: string) #nz (#k:parser_kind nz _) (#t:_) (#p:parser k t) #inv #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) = 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 input 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
val validate_filter_with_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] la:eloc) (a: t -> action (p `parse_filter` f) inva la b bool) : validate_with_action_t #nz (p `parse_filter` f) (conj_inv inv inva) (eloc_union l la) false let validate_filter_with_action (name: string) #nz (#k: parser_kind nz _) (#t: _) (#p: parser k t) #inv #l (v: validate_with_action_t p inv l true) (r: leaf_reader p) (f: (t -> bool)) (cr: string) (cf: string) (#b: bool) #inva (#la: eloc) (a: (t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool)) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) (conj_inv inv inva) (eloc_union l la) false) =
false
null
false
fun ctxt error_handler_fn input input_length start_position -> [@@ inline_let ]let pos0 = start_position in let h = HST.get () in LPC.parse_filter_eq p f (I.get_remaining input h); [@@ (rename_let ("positionAfter" ^ name)) ]let res = v ctxt error_handler_fn input input_length pos0 in let h1 = HST.get () in if LPE.is_error res then res else (LowStar.Comment.comment cr; [@@ (rename_let ("" ^ name)) ]let field_value = r input pos0 in LowStar.Comment.comment (normalize_term ("start: " ^ cf)); [@@ (rename_let (name ^ "ConstraintIsOk")) ]let ok = f field_value in LowStar.Comment.comment (normalize_term ("end: " ^ cf)); if ok then let h15 = HST.get () in let _ = modifies_address_liveness_insensitive_unused_in h h15 in if a field_value ctxt input 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)
{ "checked_file": "EverParse3d.Actions.Base.fst.checked", "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.Seq.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.Classical.fsti.checked", "EverParse3d.Prelude.fst.checked", "EverParse3d.Kinds.fst.checked", "EverParse3d.InputStream.Base.fst.checked", "EverParse3d.InputStream.All.fsti.checked", "EverParse3d.ErrorCode.fst.checked", "C.Loops.fst.checked" ], "interface_file": true, "source_file": "EverParse3d.Actions.Base.fst" }
[ "total" ]
[ "Prims.string", "Prims.bool", "EverParse3d.Kinds.parser_kind", "EverParse3d.Kinds.WeakKindStrongPrefix", "EverParse3d.Prelude.parser", "EverParse3d.Actions.Base.slice_inv", "EverParse3d.Actions.Base.eloc", "EverParse3d.Actions.Base.validate_with_action_t", "EverParse3d.Actions.Base.leaf_reader", "EverParse3d.Actions.Base.action", "EverParse3d.Kinds.filter_kind", "LowParse.Spec.Combinators.parse_filter_refine", "LowParse.Spec.Combinators.parse_filter", "EverParse3d.InputStream.Base.extra_t", "EverParse3d.Actions.Base.input_buffer_t", "EverParse3d.InputStream.All.inst", "EverParse3d.Actions.Base.app_ctxt", "EverParse3d.Actions.Base.error_handler", "EverParse3d.InputStream.Base.tlen", "EverParse3d.ErrorCode.pos_t", "EverParse3d.ErrorCode.is_error", "FStar.UInt64.t", "EverParse3d.ErrorCode.set_validator_error_pos", "EverParse3d.ErrorCode.validator_error_action_failed", "Prims.unit", "LowStar.Monotonic.Buffer.modifies_address_liveness_insensitive_unused_in", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "EverParse3d.ErrorCode.validator_error_constraint_failed", "LowStar.Comment.comment", "FStar.Pervasives.normalize_term", "Prims.op_Hat", "LowParse.Spec.Combinators.parse_filter_eq", "EverParse3d.InputStream.Base.get_remaining", "LowParse.Spec.Combinators.parse_filter_kind", "EverParse3d.Actions.Base.conj_inv", "EverParse3d.Actions.Base.eloc_union", "EverParse3d.Prelude.refine", "EverParse3d.Prelude.parse_filter" ]
[]
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 LPE = EverParse3d.ErrorCode open FStar.Tactics.Typeclasses module B = LowStar.Buffer module U8 = FStar.UInt8 module P = EverParse3d.Prelude let hinv = HS.mem -> Tot Type0 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 = loc -> mem_inv let inv_implies (inv0 inv1:slice_inv) = forall i h. inv0 i h ==> inv1 i h let true_inv : slice_inv = fun _ _ -> True let conj_inv (i0 i1:slice_inv) : slice_inv = fun sl h -> i0 sl h /\ i1 sl 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 inv_implies_refl inv = () let inv_implies_true inv0 = () let inv_implies_conj inv0 inv1 inv2 h01 h02 = () let eloc_includes_none l = () let eloc_includes_union l0 l1 l2 h01 h02 = () let 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 = fun (sl:_) h -> B.live h x let app_ctxt = B.pointer U8.t let app_loc (x:app_ctxt) (l:eloc) : eloc = B.loc_buffer x `loc_union` l inline_for_extraction noextract let input_buffer_t = EverParse3d.InputStream.All.t let action p inv l on_success a = (# [tcresolve ()] I.extra_t #input_buffer_t) -> ctxt: app_ctxt -> sl: input_buffer_t -> pos: LPE.pos_t -> posf: LPE.pos_t -> Stack a (requires fun h -> I.live sl h /\ inv (I.footprint sl) 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 (I.footprint sl) 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 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 (I.footprint sl) 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 (I.footprint sl) h1) inline_for_extraction noextract let validate_with_action_t' (#k:LP.parser_kind) (#t:Type) (p:LP.parser k t) (inv:slice_inv) (l:eloc) (allow_reading:bool) = (# [tcresolve ()] 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 /\ inv (I.footprint sl) 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 (I.footprint sl) 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 l allow_reading = validate_with_action_t' p inv 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 sl pos posf -> LPL.comment s; a ctxt sl pos posf let leaf_reader #nz #k (#t: Type) (p: parser k t) : Tot Type = (# [FStar.Tactics.Typeclasses.tcresolve ()] _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:_) (#l1:eloc) (v1:validate_with_action_t p1 inv1 l1 false) (#inv2:_) (#l2:eloc) #b (a:action p1 inv2 l2 b bool) : validate_with_action_t p1 (conj_inv inv1 inv2) (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 input 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) (#l:eloc) (v: validate_with_action_t' p inv l true) : Tot (validate_with_action_t' p inv 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) (#l:eloc) #allow_reading (v: validate_with_action_t' p inv l allow_reading) : Tot (validate_with_action_t' p inv 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:_) (#l1:eloc) (#ar:_) (v1:validate_with_action_t p1 inv1 l1 ar) : validate_with_action_t p1 inv1 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 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:_) (#l1:eloc) (#ar1:_) (v1:validate_with_action_t p1 inv1 l1 ar1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) #t2 (#p2:parser k2 t2) (#inv2:_) (#l2:eloc) (#ar2:_) (v2:validate_with_action_t p2 inv2 l2 ar2) : validate_with_action_t (p1 `parse_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false = 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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: _) (#l1: _) (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f) -> parser k2 (t2 x)) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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: _) (l1: _) (f: t1 -> bool) (#inv1': _) (#l1': _) (#b: _) (a:t1 -> action p1 inv1' l1' b bool) (#nz2: _) (#wk2: _) (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) (#inv2: _) (#l2: _) (#ar2: _) (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 input 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) (f: t1 -> bool) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:refine _ f -> Type) (#p2:(x:refine _ f -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (l1 `eloc_union` (l1' `eloc_union` l2)) false) = 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 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 #l1 (v1:validate_with_action_t p1 inv1 l1 true) (r1: leaf_reader p1) #inv1' #l1' #b (a:t1 -> action p1 inv1' l1' b bool) #nz2 #wk2 (#k2:parser_kind nz2 wk2) (#t2:t1 -> Type) (#p2:(x:t1 -> parser k2 (t2 x))) #inv2 #l2 #ar2 (v2:(x:t1 -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t (p1 `(parse_dep_pair #nz1)` p2) (conj_inv inv1 (conj_inv inv1' inv2)) (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 #_ #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 input 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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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: _) (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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Pure (validate_with_action_t ((p1 `LPC.parse_filter` f) `(parse_dep_pair #nz1)` p2) (conj_inv inv1 inv2) (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 #l1 (v1:validate_with_action_t p1 inv1 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 #l2 #ar2 (v2:(x:refine _ f -> validate_with_action_t (p2 x) inv2 l2 ar2)) : Tot (validate_with_action_t ((p1 `parse_filter` f) `parse_dep_pair` p2) (conj_inv inv1 inv2) (l1 `eloc_union` l2) false) = 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 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) : Tot (validate_with_action_t #nz #WeakKindStrongPrefix (p `LPC.parse_filter` f) inv l false) = 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 #l (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) #inva (#la:eloc) (a: t -> action #nz #WeakKindStrongPrefix #(filter_kind k) #_ (p `LPC.parse_filter` f) inva la b bool)
false
false
EverParse3d.Actions.Base.fst
{ "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" }
null
val validate_filter_with_action (name: string) (#nz:_) (#k:parser_kind nz WeakKindStrongPrefix) (#t:Type) (#[@@@erasable] p:parser k t) (#[@@@erasable] inv:slice_inv) (#[@@@erasable] l:eloc) (v:validate_with_action_t p inv l true) (r:leaf_reader p) (f:t -> bool) (cr:string) (cf:string) (#b:bool) (#[@@@erasable] inva:slice_inv) (#[@@@erasable] la:eloc) (a: t -> action (p `parse_filter` f) inva la b bool) : validate_with_action_t #nz (p `parse_filter` f) (conj_inv inv inva) (eloc_union l la) false
[]
EverParse3d.Actions.Base.validate_filter_with_action
{ "file_name": "src/3d/prelude/EverParse3d.Actions.Base.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
name: Prims.string -> v: EverParse3d.Actions.Base.validate_with_action_t p inv l true -> r: EverParse3d.Actions.Base.leaf_reader p -> f: (_: t -> Prims.bool) -> cr: Prims.string -> cf: Prims.string -> a: (_: t -> EverParse3d.Actions.Base.action (EverParse3d.Prelude.parse_filter p f) inva la b Prims.bool) -> EverParse3d.Actions.Base.validate_with_action_t (EverParse3d.Prelude.parse_filter p f) (EverParse3d.Actions.Base.conj_inv inv inva) (EverParse3d.Actions.Base.eloc_union l la) false
{ "end_col": 7, "end_line": 706, "start_col": 4, "start_line": 682 }