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 write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res | val write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f)) = | false | null | false | fun x #rrel #rel input pos ->
[@@ inline_let ]let _ = serialized_length_eq s x in
[@@ inline_let ]let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h p f input pos in
res | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"Prims.bool",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Combinators.valid_filter",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.Combinators.serialize_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f)) | [] | LowParse.Low.Combinators.write_filter | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s32: LowParse.Low.Base.leaf_writer_strong s -> f: (_: t -> Prims.GTot Prims.bool)
-> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.Combinators.serialize_filter s f) | {
"end_col": 5,
"end_line": 1122,
"start_col": 2,
"start_line": 1116
} |
Prims.Tot | val validate_synth
(#k: parser_kind)
(#t1 #t2: Type)
(#p1: parser k t1)
(p1': validator p1)
(f2: (t1 -> GTot t2))
(u: unit{synth_injective f2})
: Tot (validator (parse_synth p1 f2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos | val validate_synth
(#k: parser_kind)
(#t1 #t2: Type)
(#p1: parser k t1)
(p1': validator p1)
(f2: (t1 -> GTot t2))
(u: unit{synth_injective f2})
: Tot (validator (parse_synth p1 f2))
let validate_synth
(#k: parser_kind)
(#t1 #t2: Type)
(#p1: parser k t1)
(p1': validator p1)
(f2: (t1 -> GTot t2))
(u: unit{synth_injective f2})
: Tot (validator (parse_synth p1 f2)) = | false | null | false | fun (#rrel: _) (#rel: _) (input: slice rrel rel) pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"Prims.unit",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.Combinators.valid_synth",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.parse_synth"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
}) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_synth
(#k: parser_kind)
(#t1 #t2: Type)
(#p1: parser k t1)
(p1': validator p1)
(f2: (t1 -> GTot t2))
(u: unit{synth_injective f2})
: Tot (validator (parse_synth p1 f2)) | [] | LowParse.Low.Combinators.validate_synth | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1': LowParse.Low.Base.validator p1 ->
f2: (_: t1 -> Prims.GTot t2) ->
u106: u108: Prims.unit{LowParse.Spec.Combinators.synth_injective f2}
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_synth p1 f2) | {
"end_col": 15,
"end_line": 249,
"start_col": 2,
"start_line": 245
} |
FStar.Pervasives.Lemma | val valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==>
(valid p h input pos /\ f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f)
h
input
pos
(contents p h input pos)
(get_valid_pos p h input pos))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos) | val valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==>
(valid p h input pos /\ f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f)
h
input
pos
(contents p h input pos)
(get_valid_pos p h input pos)))
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==>
(valid p h input pos /\ f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f)
h
input
pos
(contents p h input pos)
(get_valid_pos p h input pos))) = | false | null | true | valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len then parse_filter_eq p f (bytes_of_slice_from h input pos) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.bool",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Spec.Combinators.parse_filter_eq",
"LowParse.Slice.bytes_of_slice_from",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"Prims.l_True",
"Prims.squash",
"Prims.l_imp",
"Prims.l_or",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"Prims.b2t",
"LowParse.Low.Base.Spec.contents",
"Prims.eq2",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==>
(valid p h input pos /\ f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f)
h
input
pos
(contents p h input pos)
(get_valid_pos p h input pos))) | [] | LowParse.Low.Combinators.valid_filter | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
p: LowParse.Spec.Base.parser k t ->
f: (_: t -> Prims.GTot Prims.bool) ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.Combinators.parse_filter p f) h input pos \/
LowParse.Low.Base.Spec.valid p h input pos /\
f (LowParse.Low.Base.Spec.contents p h input pos) ==>
LowParse.Low.Base.Spec.valid p h input pos /\
f (LowParse.Low.Base.Spec.contents p h input pos) == true /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Combinators.parse_filter p f)
h
input
pos
(LowParse.Low.Base.Spec.contents p h input pos)
(LowParse.Low.Base.Spec.get_valid_pos p h input pos)) | {
"end_col": 60,
"end_line": 1003,
"start_col": 2,
"start_line": 1000
} |
Prims.Tot | val serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1 {k1.parser_kind_subkind == Some ParserStrong})
(#k2: parser_kind)
(#t2: (t1 -> Tot Type))
(#p2: (x: t1 -> Tot (parser k2 (t2 x))))
(#s2: (x: t1 -> Tot (serializer (p2 x))))
(s2': (x: t1 -> serializer32 (s2 x)))
: Tot (serializer32 (serialize_dtuple2 s1 s2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos | val serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1 {k1.parser_kind_subkind == Some ParserStrong})
(#k2: parser_kind)
(#t2: (t1 -> Tot Type))
(#p2: (x: t1 -> Tot (parser k2 (t2 x))))
(#s2: (x: t1 -> Tot (serializer (p2 x))))
(s2': (x: t1 -> serializer32 (s2 x)))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1 {k1.parser_kind_subkind == Some ParserStrong})
(#k2: parser_kind)
(#t2: (t1 -> Tot Type))
(#p2: (x: t1 -> Tot (parser k2 (t2 x))))
(#s2: (x: t1 -> Tot (serializer (p2 x))))
(s2': (x: t1 -> serializer32 (s2 x)))
: Tot (serializer32 (serialize_dtuple2 s1 s2)) = | false | null | false | fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@@ inline_let ]let _ = serialize_dtuple2_eq s1 s2 x in
match x with | (| x1 , x2 |) -> serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"Prims.dtuple2",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowParse.Low.Combinators.serialize32_nondep_then_aux",
"Prims.unit",
"LowParse.Spec.Combinators.serialize_dtuple2_eq",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_dtuple2",
"LowParse.Spec.Combinators.serialize_dtuple2"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1 {k1.parser_kind_subkind == Some ParserStrong})
(#k2: parser_kind)
(#t2: (t1 -> Tot Type))
(#p2: (x: t1 -> Tot (parser k2 (t2 x))))
(#s2: (x: t1 -> Tot (serializer (p2 x))))
(s2': (x: t1 -> serializer32 (s2 x)))
: Tot (serializer32 (serialize_dtuple2 s1 s2)) | [] | LowParse.Low.Combinators.serialize32_dtuple2 | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s1':
LowParse.Low.Base.serializer32 s1
{ Mkparser_kind'?.parser_kind_subkind k1 ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong } ->
s2': (x: t1 -> LowParse.Low.Base.serializer32 (s2 x))
-> LowParse.Low.Base.serializer32 (LowParse.Spec.Combinators.serialize_dtuple2 s1 s2) | {
"end_col": 56,
"end_line": 410,
"start_col": 2,
"start_line": 405
} |
Prims.Tot | val validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter p f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res | val validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter p f))
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter p f)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va) then set_validator_error_pos_and_code validator_error_generic pos c else res | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Low.Base.leaf_reader",
"Prims.bool",
"Prims.eq2",
"LowParse.Low.ErrorCode.error_code",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"LowParse.Low.ErrorCode.maybe_set_validator_error_pos_and_code",
"Prims.op_Negation",
"LowParse.Low.ErrorCode.set_validator_error_pos_and_code",
"LowParse.Low.ErrorCode.validator_error_generic",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"Prims.unit",
"LowParse.Low.Combinators.valid_filter",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter p f)) | [] | LowParse.Low.Combinators.validate_filter_with_error_code | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
v32: LowParse.Low.Base.validator p ->
p32: LowParse.Low.Base.leaf_reader p ->
f: (_: t -> Prims.GTot Prims.bool) ->
f': (x: t -> y: Prims.bool{y == f x}) ->
c: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_filter p f) | {
"end_col": 12,
"end_line": 1048,
"start_col": 2,
"start_line": 1038
} |
Prims.Tot | val write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_weak s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ())) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos' | val write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_weak s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_weak s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ())) = | false | null | false | fun x #rrel #rel input pos ->
[@@ inline_let ]let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@@ inline_let ]let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@@ inline_let ]let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@@ inline_let ]let _ = valid_synth h p1 f2 input pos in
pos' | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_weak",
"Prims.eq2",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Combinators.valid_synth",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.Combinators.serialize_synth_eq"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_weak s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ())) | [] | LowParse.Low.Combinators.write_synth_weak | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s1': LowParse.Low.Base.leaf_writer_weak s1 ->
f2: (_: t1 -> Prims.GTot t2) ->
g1: (_: t2 -> Prims.GTot t1) ->
g1': (x2: t2 -> x1: t1{x1 == g1 x2}) ->
u501:
Prims.squash (LowParse.Spec.Combinators.synth_injective f2 /\
LowParse.Spec.Combinators.synth_inverse f2 g1)
-> LowParse.Low.Base.leaf_writer_weak (LowParse.Spec.Combinators.serialize_synth p1 f2 s1 g1 ()) | {
"end_col": 6,
"end_line": 1261,
"start_col": 2,
"start_line": 1254
} |
Prims.Tot | val read_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u | val read_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2))
let read_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) = | false | null | false | read_synth p1 f2 (fun x -> f2 x) p1' u | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.leaf_reader",
"Prims.unit",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Combinators.read_synth",
"Prims.eq2",
"LowParse.Spec.Combinators.parse_synth"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
}) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) | [] | LowParse.Low.Combinators.read_synth' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f2: (_: t1 -> t2) ->
p1': LowParse.Low.Base.leaf_reader p1 ->
u463: u465: Prims.unit{LowParse.Spec.Combinators.synth_injective f2}
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.Combinators.parse_synth p1 f2) | {
"end_col": 40,
"end_line": 1184,
"start_col": 2,
"start_line": 1184
} |
Prims.Tot | val serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ())) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos | val serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ())) = | false | null | false | fun x #rrel #rel input pos ->
[@@ inline_let ]let _ = serialize_synth_eq p1 f2 s1 g1 () x in
s1' (g1' x) input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"Prims.eq2",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Spec.Combinators.synth_inverse",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Spec.Combinators.serialize_synth_eq",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.Combinators.serialize_synth"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ())) | [] | LowParse.Low.Combinators.serialize32_synth | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s1': LowParse.Low.Base.serializer32 s1 ->
f2: (_: t1 -> Prims.GTot t2) ->
g1: (_: t2 -> Prims.GTot t1) ->
g1': (x2: t2 -> x1: t1{x1 == g1 x2}) ->
u511:
Prims.squash (LowParse.Spec.Combinators.synth_injective f2 /\
LowParse.Spec.Combinators.synth_inverse f2 g1)
-> LowParse.Low.Base.serializer32 (LowParse.Spec.Combinators.serialize_synth p1 f2 s1 g1 ()) | {
"end_col": 23,
"end_line": 1280,
"start_col": 2,
"start_line": 1276
} |
FStar.Pervasives.Lemma | val valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2)
h
s
pos
(contents p1 h s pos, contents p2 h s pos1)
(get_valid_pos p2 h s pos1))))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end | val valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2)
h
s
pos
(contents p1 h s pos, contents p2 h s pos1)
(get_valid_pos p2 h s pos1)))))
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2)
h
s
pos
(contents p1 h s pos, contents p2 h s pos1)
(get_valid_pos p2 h s pos1))))) = | false | null | true | valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then
(nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_dec",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.bool",
"Prims.unit",
"LowParse.Spec.Combinators.nondep_then_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Slice.live_slice",
"Prims.squash",
"Prims.l_imp",
"Prims.l_or",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid_content_pos",
"FStar.Pervasives.Native.Mktuple2",
"LowParse.Low.Base.Spec.contents",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2)
h
s
pos
(contents p1 h s pos, contents p2 h s pos1)
(get_valid_pos p2 h s pos1))))) | [] | LowParse.Low.Combinators.valid_nondep_then | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
p1: LowParse.Spec.Base.parser k1 t1 ->
p2: LowParse.Spec.Base.parser k2 t2 ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Slice.live_slice h s)
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.Combinators.nondep_then p1 p2) h s pos \/
LowParse.Low.Base.Spec.valid p1 h s pos /\
LowParse.Low.Base.Spec.valid p2 h s (LowParse.Low.Base.Spec.get_valid_pos p1 h s pos) ==>
LowParse.Low.Base.Spec.valid p1 h s pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos p1 h s pos in
LowParse.Low.Base.Spec.valid p2 h s (LowParse.Low.Base.Spec.get_valid_pos p1 h s pos) /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Combinators.nondep_then p1 p2)
h
s
pos
(LowParse.Low.Base.Spec.contents p1 h s pos, LowParse.Low.Base.Spec.contents p2 h s pos1
)
(LowParse.Low.Base.Spec.get_valid_pos p2 h s pos1))) | {
"end_col": 5,
"end_line": 45,
"start_col": 2,
"start_line": 35
} |
Prims.Tot | val write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_strong s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ())) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos' | val write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_strong s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_strong s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ())) = | false | null | false | fun x #rrel #rel input pos ->
[@@ inline_let ]let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@@ inline_let ]let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@@ inline_let ]let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@@ inline_let ]let _ = valid_synth h p1 f2 input pos in
pos' | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_strong",
"Prims.eq2",
"Prims.squash",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Combinators.valid_synth",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Spec.Combinators.serialize_synth",
"LowParse.Spec.Combinators.serialize_synth_eq"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1': leaf_writer_strong s1)
(#t2: Type)
(f2: (t1 -> GTot t2))
(g1: (t2 -> GTot t1))
(g1': (x2: t2 -> Tot (x1: t1{x1 == g1 x2})))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ())) | [] | LowParse.Low.Combinators.write_synth | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s1': LowParse.Low.Base.leaf_writer_strong s1 ->
f2: (_: t1 -> Prims.GTot t2) ->
g1: (_: t2 -> Prims.GTot t1) ->
g1': (x2: t2 -> x1: t1{x1 == g1 x2}) ->
u491:
Prims.squash (LowParse.Spec.Combinators.synth_injective f2 /\
LowParse.Spec.Combinators.synth_inverse f2 g1)
-> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.Combinators.serialize_synth p1 f2 s1 g1 ()) | {
"end_col": 6,
"end_line": 1239,
"start_col": 2,
"start_line": 1232
} |
Prims.Tot | val accessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(#pt: parser kt tag_t)
(jt: jumper pt)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot (accessor (gaccessor_tagged_union_payload pt tag_of_data p t)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(#pt: parser kt tag_t)
(jt: jumper pt)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (accessor (gaccessor_tagged_union_payload pt tag_of_data p t))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
valid_facts (parse_tagged_union pt tag_of_data p) h input pos;
parse_tagged_union_eq pt tag_of_data p (bytes_of_slice_from h input pos);
valid_facts pt h input pos
in
let res = jt input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_tagged_union_payload pt tag_of_data p t) input pos
in
res | val accessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(#pt: parser kt tag_t)
(jt: jumper pt)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot (accessor (gaccessor_tagged_union_payload pt tag_of_data p t))
let accessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(#pt: parser kt tag_t)
(jt: jumper pt)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot (accessor (gaccessor_tagged_union_payload pt tag_of_data p t)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
valid_facts (parse_tagged_union pt tag_of_data p) h input pos;
parse_tagged_union_eq pt tag_of_data p (bytes_of_slice_from h input pos);
valid_facts pt h input pos
in
let res = jt input pos in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_tagged_union_payload pt tag_of_data p t) input pos
in
res | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Low.Combinators.clens_tagged_union_payload",
"LowParse.Low.Combinators.gaccessor_tagged_union_payload",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"LowParse.Slice.bytes_of_slice_from",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos
let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
= {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t));
}
let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
match parse pt input with
| Some (t', consumed_t) ->
consumed_t
| _ -> 0 (* dummy *)
let gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
injective_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_injective (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl'
let gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
(and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_strong_prefix (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl'
let gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_tagged_union_payload_injective pt tag_of_data p t x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_tagged_union_payload_no_lookahead pt tag_of_data p t x));
gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) (gaccessor_tagged_union_payload' pt tag_of_data p t);
gaccessor_tagged_union_payload' pt tag_of_data p t
inline_for_extraction
let accessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(#pt: parser kt tag_t)
(jt: jumper pt)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(#pt: parser kt tag_t)
(jt: jumper pt)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot (accessor (gaccessor_tagged_union_payload pt tag_of_data p t)) | [] | LowParse.Low.Combinators.accessor_tagged_union_payload | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
jt: LowParse.Low.Base.jumper pt ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t)) ->
t: tag_t
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_tagged_union_payload pt
tag_of_data
p
t) | {
"end_col": 5,
"end_line": 1563,
"start_col": 2,
"start_line": 1552
} |
Prims.Tot | val validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos | val validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@@ inline_let ]let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r) then set_validator_error_pos_and_code validator_error_generic pos c else pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"Prims.bool",
"Prims.eq2",
"LowParse.Low.ErrorCode.error_code",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"Prims.op_Negation",
"LowParse.Low.ErrorCode.set_validator_error_pos_and_code",
"LowParse.Low.ErrorCode.validator_error_generic",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Combinators.parse_ret_kind",
"LowParse.Spec.Combinators.parse_ret",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.Combinators.valid_filter",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.validator",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f)) | [] | LowParse.Low.Combinators.validate_filter_ret_with_error_code | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
r: t ->
f: (_: t -> Prims.GTot Prims.bool) ->
f': (x: t -> y: Prims.bool{y == f x}) ->
c: LowParse.Low.ErrorCode.error_code
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_filter (LowParse.Spec.Combinators.parse_ret
r)
f) | {
"end_col": 10,
"end_line": 1079,
"start_col": 2,
"start_line": 1073
} |
Prims.Tot | val accessor_synth_inv
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth_inv p1 f g u)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos | val accessor_synth_inv
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth_inv p1 f g u))
let accessor_synth_inv
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth_inv p1 f g u)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.unit",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth_inv",
"LowParse.Low.Combinators.gaccessor_synth_inv",
"FStar.Classical.forall_intro",
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_synth_inv'",
"LowParse.Low.Combinators.gaccessor_synth_inv_eq",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } ) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_synth_inv
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth_inv p1 f g u)) | [] | LowParse.Low.Combinators.accessor_synth_inv | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u232:
u235:
Prims.unit
{LowParse.Spec.Combinators.synth_inverse f g /\ LowParse.Spec.Combinators.synth_injective f}
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_synth_inv p1 f g u232) | {
"end_col": 5,
"end_line": 654,
"start_col": 2,
"start_line": 648
} |
Prims.Tot | val validate_strengthen
(k2 #k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos | val validate_strengthen
(k2 #k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
let validate_strengthen
(k2 #k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@@ inline_let ]let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"Prims.squash",
"LowParse.Spec.Base.parser_kind_prop",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Spec.Base.strengthen",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_strengthen
(k2 #k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1)) | [] | LowParse.Low.Combinators.validate_strengthen | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
k2: LowParse.Spec.Base.parser_kind ->
v1: LowParse.Low.Base.validator p1 ->
sq: Prims.squash (LowParse.Spec.Base.parser_kind_prop k2 p1)
-> LowParse.Low.Base.validator (LowParse.Spec.Base.strengthen k2 p1) | {
"end_col": 14,
"end_line": 1372,
"start_col": 2,
"start_line": 1366
} |
FStar.HyperStack.ST.Stack | val serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2': serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\ U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h))
(ensures
(fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\
(B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
((serialize s1 x1) `Seq.append` (serialize s2 x2))))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2 | val serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2': serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\ U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h))
(ensures
(fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\
(B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
((serialize s1 x1) `Seq.append` (serialize s2 x2)))))
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2': serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\ U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h))
(ensures
(fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\
(B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
((serialize s1 x1) `Seq.append` (serialize s2 x2))))) = | true | null | false | let gpos' =
Ghost.hide (pos
`U32.add`
(U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))))
in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"FStar.UInt32.add",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.frame_serializer32",
"FStar.Ghost.hide",
"FStar.Ghost.erased",
"FStar.UInt32.uint_to_t",
"Prims.op_Addition",
"FStar.Seq.Base.length",
"LowParse.Spec.Base.serialize",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowStar.Monotonic.Buffer.length",
"LowParse.Low.Base.writable",
"FStar.Seq.Base.seq",
"LowStar.Monotonic.Buffer.as_seq",
"Prims.int",
"Prims.nat",
"Prims.eq2",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_buffer_from_to",
"FStar.Seq.Base.equal",
"FStar.Seq.Base.slice",
"FStar.Seq.Base.append"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1': serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2': serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel #rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires
(fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\ U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h))
(ensures
(fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\
(B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\ B.live h b /\
(Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len))
`Seq.equal`
((serialize s1 x1) `Seq.append` (serialize s2 x2))))) | [] | LowParse.Low.Combinators.serialize32_nondep_then_aux | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
s1': LowParse.Low.Base.serializer32 s1 ->
s2': LowParse.Low.Base.serializer32 s2 ->
x1: t1 ->
x2: t2 ->
b: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel ->
pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack FStar.UInt32.t | {
"end_col": 21,
"end_line": 168,
"start_col": 1,
"start_line": 162
} |
Prims.Tot | val validate_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos | val validate_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
let validate_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@@ inline_let ]let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"Prims.squash",
"LowParse.Spec.Base.is_weaker_than",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Spec.Base.weaken",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2)) | [] | LowParse.Low.Combinators.validate_weaken | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
k1: LowParse.Spec.Base.parser_kind ->
v2: LowParse.Low.Base.validator p2 ->
sq: Prims.squash (LowParse.Spec.Base.is_weaker_than k1 k2)
-> LowParse.Low.Base.validator (LowParse.Spec.Base.weaken k1 p2) | {
"end_col": 14,
"end_line": 1338,
"start_col": 2,
"start_line": 1332
} |
Prims.Ghost | val gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0 | val gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos')) = | false | null | false | synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.unit",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Bytes.bytes",
"LowParse.Spec.Combinators.parse_synth_eq",
"LowParse.Spec.Combinators.synth_injective_synth_inverse_synth_inverse_recip",
"Prims.nat",
"Prims.l_True",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos')) | [] | LowParse.Low.Combinators.gaccessor_synth' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u206:
u210:
Prims.unit
{LowParse.Spec.Combinators.synth_inverse f g /\ LowParse.Spec.Combinators.synth_injective f} ->
input: LowParse.Bytes.bytes
-> Prims.Ghost Prims.nat | {
"end_col": 3,
"end_line": 542,
"start_col": 2,
"start_line": 540
} |
Prims.Tot | val accessor_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth p1 f g u)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos | val accessor_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth p1 f g u))
let accessor_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth p1 f g u)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.unit",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth",
"LowParse.Low.Combinators.gaccessor_synth",
"FStar.Classical.forall_intro",
"LowParse.Bytes.bytes",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_synth'",
"LowParse.Low.Combinators.gaccessor_synth_eq",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } ) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
: Tot (accessor (gaccessor_synth p1 f g u)) | [] | LowParse.Low.Combinators.accessor_synth | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u213:
u216:
Prims.unit
{LowParse.Spec.Combinators.synth_inverse f g /\ LowParse.Spec.Combinators.synth_injective f}
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_synth p1 f g u213) | {
"end_col": 5,
"end_line": 582,
"start_col": 2,
"start_line": 576
} |
FStar.Pervasives.Lemma | val gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ injective_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
injective_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_injective (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl' | val gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ injective_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl'))
let gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ injective_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl')) = | false | null | true | parse_injective (parse_tagged_union pt tag_of_data p) sl sl';
parse_tagged_union_eq pt tag_of_data p sl;
parse_tagged_union_eq pt tag_of_data p sl';
parse_injective pt sl sl' | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"Prims.unit",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"Prims.l_and",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Combinators.clens_tagged_union_payload",
"LowParse.Spec.Base.injective_precond",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_tagged_union_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos
let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
= {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t));
}
let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
match parse pt input with
| Some (t', consumed_t) ->
consumed_t
| _ -> 0 (* dummy *)
let gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
injective_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl' | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ injective_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl')) | [] | LowParse.Low.Combinators.gaccessor_tagged_union_payload_injective | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t)) ->
t: tag_t ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
(p t)
(LowParse.Low.Combinators.clens_tagged_union_payload tag_of_data t)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
(p t)
(LowParse.Low.Combinators.clens_tagged_union_payload tag_of_data t)
sl' /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
sl
sl')
(ensures
LowParse.Low.Combinators.gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
LowParse.Low.Combinators.gaccessor_tagged_union_payload' pt tag_of_data p t sl') | {
"end_col": 27,
"end_line": 1498,
"start_col": 2,
"start_line": 1495
} |
Prims.Tot | val validate_ret (#t: Type) (v: t) : Tot (validator (parse_ret v)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL () | val validate_ret (#t: Type) (v: t) : Tot (validator (parse_ret v))
let validate_ret (#t: Type) (v: t) : Tot (validator (parse_ret v)) = | false | null | false | validate_total_constant_size (parse_ret v) 0uL () | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Low.Base.validate_total_constant_size",
"LowParse.Spec.Combinators.parse_ret_kind",
"LowParse.Spec.Combinators.parse_ret",
"FStar.UInt64.__uint_to_t",
"LowParse.Low.Base.validator"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_ret (#t: Type) (v: t) : Tot (validator (parse_ret v)) | [] | LowParse.Low.Combinators.validate_ret | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | v: t -> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_ret v) | {
"end_col": 51,
"end_line": 417,
"start_col": 2,
"start_line": 417
} |
Prims.Tot | val make_total_constant_size_reader
(sz: nat)
(sz': U32.t{U32.v sz' == sz})
(#t: Type)
(f: (s: bytes{Seq.length s == sz} -> GTot (t)))
(u: unit{make_total_constant_size_parser_precond sz t f})
(f':
(#rrel: _ -> #rel: _ -> s: B.mbuffer byte rrel rel -> pos: U32.t
-> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos | val make_total_constant_size_reader
(sz: nat)
(sz': U32.t{U32.v sz' == sz})
(#t: Type)
(f: (s: bytes{Seq.length s == sz} -> GTot (t)))
(u: unit{make_total_constant_size_parser_precond sz t f})
(f':
(#rrel: _ -> #rel: _ -> s: B.mbuffer byte rrel rel -> pos: U32.t
-> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
let make_total_constant_size_reader
(sz: nat)
(sz': U32.t{U32.v sz' == sz})
(#t: Type)
(f: (s: bytes{Seq.length s == sz} -> GTot (t)))
(u: unit{make_total_constant_size_parser_precond sz t f})
(f':
(#rrel: _ -> #rel: _ -> s: B.mbuffer byte rrel rel -> pos: U32.t
-> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f)) = | false | null | false | fun #rrel #rel sl pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"Prims.nat",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"LowParse.Bytes.bytes",
"FStar.Seq.Base.length",
"LowParse.Bytes.byte",
"Prims.unit",
"LowParse.Spec.Combinators.make_total_constant_size_parser_precond",
"LowStar.Monotonic.Buffer.srel",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"LowStar.Monotonic.Buffer.live",
"Prims.op_LessThanOrEqual",
"Prims.op_Addition",
"LowStar.Monotonic.Buffer.length",
"LowStar.Monotonic.Buffer.modifies",
"LowStar.Monotonic.Buffer.loc_none",
"FStar.Seq.Base.slice",
"LowStar.Monotonic.Buffer.as_seq",
"LowParse.Slice.srel",
"LowParse.Slice.slice",
"LowParse.Slice.buffer_srel_of_srel",
"LowParse.Slice.__proj__Mkslice__item__base",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.total_constant_size_parser_kind",
"LowParse.Spec.Combinators.make_total_constant_size_parser",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.leaf_reader"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
)))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val make_total_constant_size_reader
(sz: nat)
(sz': U32.t{U32.v sz' == sz})
(#t: Type)
(f: (s: bytes{Seq.length s == sz} -> GTot (t)))
(u: unit{make_total_constant_size_parser_precond sz t f})
(f':
(#rrel: _ -> #rel: _ -> s: B.mbuffer byte rrel rel -> pos: U32.t
-> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures
(fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f)) | [] | LowParse.Low.Combinators.make_total_constant_size_reader | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
sz: Prims.nat ->
sz': FStar.UInt32.t{FStar.UInt32.v sz' == sz} ->
f: (s: LowParse.Bytes.bytes{FStar.Seq.Base.length s == sz} -> Prims.GTot t) ->
u385: u390: Prims.unit{LowParse.Spec.Combinators.make_total_constant_size_parser_precond sz t f} ->
f':
(s: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel -> pos: FStar.UInt32.t
-> FStar.HyperStack.ST.Stack t)
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.Combinators.make_total_constant_size_parser sz t f
) | {
"end_col": 16,
"end_line": 982,
"start_col": 2,
"start_line": 979
} |
FStar.Pervasives.Lemma | val gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
(and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_strong_prefix (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl' | val gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl'))
let gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl')) = | false | null | true | parse_strong_prefix (parse_tagged_union pt tag_of_data p) sl sl';
parse_tagged_union_eq pt tag_of_data p sl;
parse_tagged_union_eq pt tag_of_data p sl';
parse_injective pt sl sl' | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"Prims.unit",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"LowParse.Spec.Base.parse_strong_prefix",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Combinators.clens_tagged_union_payload",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.squash",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_tagged_union_payload'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos
let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
= {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t));
}
let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
match parse pt input with
| Some (t', consumed_t) ->
consumed_t
| _ -> 0 (* dummy *)
let gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
injective_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_injective (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl'
let gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
(and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl' | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
sl' /\ no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'))
(ensures
(gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
gaccessor_tagged_union_payload' pt tag_of_data p t sl')) | [] | LowParse.Low.Combinators.gaccessor_tagged_union_payload_no_lookahead | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t)) ->
t: tag_t ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Combinators.and_then_kind kt k) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
(p t)
(LowParse.Low.Combinators.clens_tagged_union_payload tag_of_data t)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
(p t)
(LowParse.Low.Combinators.clens_tagged_union_payload tag_of_data t)
sl' /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
sl
sl')
(ensures
LowParse.Low.Combinators.gaccessor_tagged_union_payload' pt tag_of_data p t sl ==
LowParse.Low.Combinators.gaccessor_tagged_union_payload' pt tag_of_data p t sl') | {
"end_col": 27,
"end_line": 1523,
"start_col": 2,
"start_line": 1520
} |
Prims.Tot | val jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': jumper p2)
: Tot (jumper (nondep_then p1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos) | val jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': jumper p2)
: Tot (jumper (nondep_then p1 p2))
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': jumper p2)
: Tot (jumper (nondep_then p1 p2)) = | false | null | false | fun (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Combinators.valid_nondep_then",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': jumper p2)
: Tot (jumper (nondep_then p1 p2)) | [] | LowParse.Low.Combinators.jump_nondep_then | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p1': LowParse.Low.Base.jumper p1 -> p2': LowParse.Low.Base.jumper p2
-> LowParse.Low.Base.jumper (LowParse.Spec.Combinators.nondep_then p1 p2) | {
"end_col": 27,
"end_line": 105,
"start_col": 2,
"start_line": 101
} |
Prims.Tot | val clens_fst (t1 t2: Type) : Tot (clens (t1 & t2) t1) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
} | val clens_fst (t1 t2: Type) : Tot (clens (t1 & t2) t1)
let clens_fst (t1 t2: Type) : Tot (clens (t1 & t2) t1) = | false | null | false | { clens_cond = (fun (x: (t1 & t2)) -> True); clens_get = fst } | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Low.Base.Spec.Mkclens",
"FStar.Pervasives.Native.tuple2",
"Prims.l_True",
"FStar.Pervasives.Native.fst",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_fst (t1 t2: Type) : Tot (clens (t1 & t2) t1) | [] | LowParse.Low.Combinators.clens_fst | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t1: Type -> t2: Type -> LowParse.Low.Base.Spec.clens (t1 * t2) t1 | {
"end_col": 18,
"end_line": 662,
"start_col": 2,
"start_line": 661
} |
Prims.Tot | val clens_synth_inv (#t1 #t2: Type) (f: (t1 -> GTot t2)) (g: (t2 -> GTot t1)) : Tot (clens t2 t1) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
} | val clens_synth_inv (#t1 #t2: Type) (f: (t1 -> GTot t2)) (g: (t2 -> GTot t1)) : Tot (clens t2 t1)
let clens_synth_inv (#t1 #t2: Type) (f: (t1 -> GTot t2)) (g: (t2 -> GTot t1)) : Tot (clens t2 t1) = | false | null | false | { clens_cond = (fun (x: t2) -> True); clens_get = (fun (x: t2) -> g x) } | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Low.Base.Spec.Mkclens",
"Prims.l_True",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_synth_inv (#t1 #t2: Type) (f: (t1 -> GTot t2)) (g: (t2 -> GTot t1)) : Tot (clens t2 t1) | [] | LowParse.Low.Combinators.clens_synth_inv | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | f: (_: t1 -> Prims.GTot t2) -> g: (_: t2 -> Prims.GTot t1) -> LowParse.Low.Base.Spec.clens t2 t1 | {
"end_col": 35,
"end_line": 592,
"start_col": 2,
"start_line": 591
} |
Prims.Tot | val jump_false:jumper parse_false | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul () | val jump_false:jumper parse_false
let jump_false:jumper parse_false = | false | null | false | jump_constant_size parse_false 0ul () | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Low.Base.jump_constant_size",
"LowParse.Spec.Combinators.parse_false_kind",
"Prims.squash",
"Prims.l_False",
"LowParse.Spec.Combinators.parse_false",
"FStar.UInt32.__uint_to_t"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction | false | true | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_false:jumper parse_false | [] | LowParse.Low.Combinators.jump_false | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | LowParse.Low.Base.jumper LowParse.Spec.Combinators.parse_false | {
"end_col": 39,
"end_line": 437,
"start_col": 2,
"start_line": 437
} |
Prims.Tot | val validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': validator p2)
: Tot (validator (nondep_then p1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1 | val validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': validator p2)
: Tot (validator (nondep_then p1 p2))
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': validator p2)
: Tot (validator (nondep_then p1 p2)) = | false | null | false | fun (#rrel: _) (#rel: _) (input: slice rrel rel) pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then pos1
else
[@@ inline_let ]let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"Prims.bool",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.Combinators.valid_nondep_then",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1': validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2': validator p2)
: Tot (validator (nondep_then p1 p2)) | [] | LowParse.Low.Combinators.validate_nondep_then | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p1': LowParse.Low.Base.validator p1 -> p2': LowParse.Low.Base.validator p2
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.nondep_then p1 p2) | {
"end_col": 18,
"end_line": 88,
"start_col": 2,
"start_line": 77
} |
Prims.Tot | val gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0 | val gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data)) = | false | null | false | fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Bytes.bytes",
"Prims.unit",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"Prims.nat",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Low.Combinators.clens_tagged_union_tag"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data)) | [] | LowParse.Low.Combinators.gaccessor_tagged_union_tag' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t))
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
pt
(LowParse.Low.Combinators.clens_tagged_union_tag tag_of_data) | {
"end_col": 5,
"end_line": 1419,
"start_col": 2,
"start_line": 1417
} |
Prims.Tot | val clens_snd (t1 t2: Type) : Tot (clens (t1 & t2) t2) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
} | val clens_snd (t1 t2: Type) : Tot (clens (t1 & t2) t2)
let clens_snd (t1 t2: Type) : Tot (clens (t1 & t2) t2) = | false | null | false | { clens_cond = (fun (x: (t1 & t2)) -> True); clens_get = snd } | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Low.Base.Spec.Mkclens",
"FStar.Pervasives.Native.tuple2",
"Prims.l_True",
"FStar.Pervasives.Native.snd",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_snd (t1 t2: Type) : Tot (clens (t1 & t2) t2) | [] | LowParse.Low.Combinators.clens_snd | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | t1: Type -> t2: Type -> LowParse.Low.Base.Spec.clens (t1 * t2) t2 | {
"end_col": 18,
"end_line": 677,
"start_col": 2,
"start_line": 676
} |
Prims.Tot | val jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(sz: U32.t{U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low})
: Tot (jumper (parse_dtuple2 p1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1 | val jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(sz: U32.t{U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low})
: Tot (jumper (parse_dtuple2 p1 p2))
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(sz: U32.t{U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low})
: Tot (jumper (parse_dtuple2 p1 p2)) = | false | null | false | fun (#rrel: _) (#rel: _) (input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@@ inline_let ]let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@@ inline_let ]let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"FStar.UInt32.t",
"Prims.l_and",
"Prims.eq2",
"Prims.int",
"Prims.l_or",
"FStar.UInt.size",
"FStar.UInt32.n",
"Prims.b2t",
"Prims.op_GreaterThanOrEqual",
"FStar.UInt32.v",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_low",
"FStar.Pervasives.Native.option",
"Prims.nat",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_high",
"FStar.Pervasives.Native.Some",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"LowParse.Low.Base.jump_constant_size'",
"LowParse.Low.Base.Spec.contents",
"Prims.unit",
"FStar.Ghost.reveal",
"LowParse.Low.Base.Spec.valid_facts",
"FStar.Ghost.erased",
"FStar.Ghost.hide",
"LowParse.Low.Combinators.valid_dtuple2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.and_then_kind",
"Prims.dtuple2",
"LowParse.Spec.Combinators.parse_dtuple2"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low }) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(sz: U32.t{U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low})
: Tot (jumper (parse_dtuple2 p1 p2)) | [] | LowParse.Low.Combinators.jump_dtuple2_constant_size_dsnd | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
v1: LowParse.Low.Base.jumper p1 ->
p2: (x: t1 -> LowParse.Spec.Base.parser k2 (t2 x)) ->
sz:
FStar.UInt32.t
{ FStar.UInt32.v sz == Mkparser_kind'?.parser_kind_low k2 /\
Mkparser_kind'?.parser_kind_high k2 ==
FStar.Pervasives.Native.Some (Mkparser_kind'?.parser_kind_low k2) }
-> LowParse.Low.Base.jumper (LowParse.Spec.Combinators.parse_dtuple2 p1 p2) | {
"end_col": 66,
"end_line": 370,
"start_col": 2,
"start_line": 363
} |
Prims.Tot | val validate_false: Prims.unit -> Tot (validator parse_false) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic | val validate_false: Prims.unit -> Tot (validator parse_false)
let validate_false () : Tot (validator parse_false) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"Prims.unit",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.validator_error_generic",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Combinators.parse_false_kind",
"Prims.squash",
"Prims.l_False",
"LowParse.Spec.Combinators.parse_false",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.validator"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction | false | true | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_false: Prims.unit -> Tot (validator parse_false) | [] | LowParse.Low.Combinators.validate_false | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | _: Prims.unit -> LowParse.Low.Base.validator LowParse.Spec.Combinators.parse_false | {
"end_col": 25,
"end_line": 429,
"start_col": 2,
"start_line": 425
} |
Prims.Tot | val validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(#p2: (x: t1 -> parser k2 (t2 x)))
(v2: (x: t1 -> Tot (validator (p2 x))))
: Tot (validator (parse_dtuple2 p1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1 | val validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(#p2: (x: t1 -> parser k2 (t2 x)))
(v2: (x: t1 -> Tot (validator (p2 x))))
: Tot (validator (parse_dtuple2 p1 p2))
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(#p2: (x: t1 -> parser k2 (t2 x)))
(v2: (x: t1 -> Tot (validator (p2 x))))
: Tot (validator (parse_dtuple2 p1 p2)) = | false | null | false | fun (#rrel: _) (#rel: _) (input: slice rrel rel) pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then pos1
else
let x = r1 input (uint64_to_uint32 pos) in
[@@ inline_let ]let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Low.Base.leaf_reader",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"Prims.bool",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.Combinators.valid_dtuple2",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.and_then_kind",
"Prims.dtuple2",
"LowParse.Spec.Combinators.parse_dtuple2"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(#p2: (x: t1 -> parser k2 (t2 x)))
(v2: (x: t1 -> Tot (validator (p2 x))))
: Tot (validator (parse_dtuple2 p1 p2)) | [] | LowParse.Low.Combinators.validate_dtuple2 | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
v1: LowParse.Low.Base.validator p1 ->
r1: LowParse.Low.Base.leaf_reader p1 ->
v2: (x: t1 -> LowParse.Low.Base.validator (p2 x))
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_dtuple2 p1 p2) | {
"end_col": 19,
"end_line": 329,
"start_col": 2,
"start_line": 317
} |
FStar.Pervasives.Lemma | val valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (synth_injective f2 /\ valid p1 h input pos))
(ensures
(valid_content_pos (parse_synth p1 f2)
h
input
pos
(f2 (contents p1 h input pos))
(get_valid_pos p1 h input pos))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos | val valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (synth_injective f2 /\ valid p1 h input pos))
(ensures
(valid_content_pos (parse_synth p1 f2)
h
input
pos
(f2 (contents p1 h input pos))
(get_valid_pos p1 h input pos)))
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (synth_injective f2 /\ valid p1 h input pos))
(ensures
(valid_content_pos (parse_synth p1 f2)
h
input
pos
(f2 (contents p1 h input pos))
(get_valid_pos p1 h input pos))) = | false | null | true | valid_synth h p1 f2 input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Combinators.valid_synth",
"Prims.unit",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Base.Spec.valid",
"Prims.squash",
"LowParse.Low.Base.Spec.valid_content_pos",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(input: slice rrel rel)
(pos: U32.t)
: Lemma (requires (synth_injective f2 /\ valid p1 h input pos))
(ensures
(valid_content_pos (parse_synth p1 f2)
h
input
pos
(f2 (contents p1 h input pos))
(get_valid_pos p1 h input pos))) | [] | LowParse.Low.Combinators.valid_synth_intro | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
p1: LowParse.Spec.Base.parser k t1 ->
f2: (_: t1 -> Prims.GTot t2) ->
input: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma
(requires
LowParse.Spec.Combinators.synth_injective f2 /\ LowParse.Low.Base.Spec.valid p1 h input pos)
(ensures
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Combinators.parse_synth p1 f2)
h
input
pos
(f2 (LowParse.Low.Base.Spec.contents p1 h input pos))
(LowParse.Low.Base.Spec.get_valid_pos p1 h input pos)) | {
"end_col": 31,
"end_line": 231,
"start_col": 2,
"start_line": 231
} |
Prims.Tot | val gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` (clens_snd _ _))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _ | val gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` (clens_snd _ _)))
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` (clens_snd _ _))) = | false | null | false | g `gaccessor_compose` (gaccessor_snd _ _) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"FStar.Pervasives.Native.tuple2",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Base.Spec.gaccessor_compose",
"LowParse.Low.Combinators.clens_snd",
"LowParse.Low.Combinators.gaccessor_snd",
"LowParse.Low.Base.Spec.clens_compose"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` (clens_snd _ _))) | [] | LowParse.Low.Combinators.gaccessor_then_snd | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | g: LowParse.Low.Base.Spec.gaccessor p0 (LowParse.Spec.Combinators.nondep_then p1 p2) cl
-> LowParse.Low.Base.Spec.gaccessor p0
p2
(LowParse.Low.Base.Spec.clens_compose cl (LowParse.Low.Combinators.clens_snd t1 t2)) | {
"end_col": 41,
"end_line": 845,
"start_col": 2,
"start_line": 845
} |
Prims.Tot | val accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k': parser_kind)
(#t': Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u | val accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k': parser_kind)
(#t': Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k': parser_kind)
(#t': Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u)) = | false | null | false | accessor_compose (accessor_fst p1 u p2) a u | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.accessor",
"Prims.squash",
"Prims.unit",
"LowParse.Low.Base.accessor_compose",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Combinators.clens_fst",
"LowParse.Low.Combinators.gaccessor_fst",
"LowParse.Low.Combinators.accessor_fst",
"LowParse.Low.Base.Spec.clens_compose",
"LowParse.Low.Combinators.gaccessor_fst_then"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k': parser_kind)
(#t': Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u)) | [] | LowParse.Low.Combinators.accessor_fst_then | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
a: LowParse.Low.Base.accessor g ->
p2: LowParse.Spec.Base.parser k2 t2 ->
u355: Prims.squash Prims.unit
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_fst_then g p2 u355) | {
"end_col": 45,
"end_line": 905,
"start_col": 2,
"start_line": 905
} |
Prims.Tot | val accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos | val accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2)) = | false | null | false | reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.unit",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Combinators.clens_fst",
"LowParse.Low.Combinators.gaccessor_fst",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2)) | [] | LowParse.Low.Combinators.accessor_fst | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k1 t1 ->
sq: Prims.squash Prims.unit ->
p2: LowParse.Spec.Base.parser k2 t2
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_fst p1 sq p2) | {
"end_col": 5,
"end_line": 887,
"start_col": 2,
"start_line": 883
} |
FStar.Pervasives.Lemma | val valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2)
h
s
pos
(| x, contents (p2 x) h s pos1 |)
(get_valid_pos (p2 x) h s pos1))))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end | val valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2)
h
s
pos
(| x, contents (p2 x) h s pos1 |)
(get_valid_pos (p2 x) h s pos1)))))
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2)
h
s
pos
(| x, contents (p2 x) h s pos1 |)
(get_valid_pos (p2 x) h s pos1))))) = | false | null | true | valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then
(parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"FStar.Monotonic.HyperStack.mem",
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.op_LessThanOrEqual",
"FStar.UInt32.v",
"LowParse.Slice.__proj__Mkslice__item__len",
"LowParse.Low.Base.Spec.valid_dec",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.Base.Spec.contents",
"LowParse.Low.Base.Spec.get_valid_pos",
"Prims.bool",
"Prims.unit",
"LowParse.Spec.Combinators.parse_dtuple2_eq",
"LowParse.Slice.bytes_of_slice_from",
"LowParse.Spec.Combinators.and_then_kind",
"Prims.dtuple2",
"LowParse.Spec.Combinators.parse_dtuple2",
"LowParse.Slice.live_slice",
"Prims.squash",
"Prims.l_imp",
"Prims.l_or",
"LowParse.Low.Base.Spec.valid",
"Prims.l_and",
"LowParse.Low.Base.Spec.valid_content_pos",
"Prims.Mkdtuple2",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: (t1 -> Type))
(p2: (x: t1 -> parser k2 (t2 x)))
(s: slice rrel rel)
(pos: U32.t)
: Lemma (requires (live_slice h s))
(ensures
((valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))) ==>
(valid p1 h s pos /\
(let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2)
h
s
pos
(| x, contents (p2 x) h s pos1 |)
(get_valid_pos (p2 x) h s pos1))))) | [] | LowParse.Low.Combinators.valid_dtuple2 | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
h: FStar.Monotonic.HyperStack.mem ->
p1: LowParse.Spec.Base.parser k1 t1 ->
p2: (x: t1 -> LowParse.Spec.Base.parser k2 (t2 x)) ->
s: LowParse.Slice.slice rrel rel ->
pos: FStar.UInt32.t
-> FStar.Pervasives.Lemma (requires LowParse.Slice.live_slice h s)
(ensures
LowParse.Low.Base.Spec.valid (LowParse.Spec.Combinators.parse_dtuple2 p1 p2) h s pos \/
LowParse.Low.Base.Spec.valid p1 h s pos /\
LowParse.Low.Base.Spec.valid (p2 (LowParse.Low.Base.Spec.contents p1 h s pos))
h
s
(LowParse.Low.Base.Spec.get_valid_pos p1 h s pos) ==>
LowParse.Low.Base.Spec.valid p1 h s pos /\
(let pos1 = LowParse.Low.Base.Spec.get_valid_pos p1 h s pos in
let x = LowParse.Low.Base.Spec.contents p1 h s pos in
LowParse.Low.Base.Spec.valid (p2 x) h s (LowParse.Low.Base.Spec.get_valid_pos p1 h s pos) /\
LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Combinators.parse_dtuple2 p1 p2)
h
s
pos
(| x, LowParse.Low.Base.Spec.contents (p2 x) h s pos1 |)
(LowParse.Low.Base.Spec.get_valid_pos (p2 x) h s pos1))) | {
"end_col": 5,
"end_line": 303,
"start_col": 2,
"start_line": 292
} |
Prims.Tot | val serialize32_false:serializer32 #_ #_ #parse_false serialize_false | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul | val serialize32_false:serializer32 #_ #_ #parse_false serialize_false
let serialize32_false:serializer32 #_ #_ #parse_false serialize_false = | false | null | false | fun _ #_ #_ _ _ -> 0ul | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"Prims.squash",
"Prims.l_False",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"FStar.UInt32.__uint_to_t"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction | false | true | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_false:serializer32 #_ #_ #parse_false serialize_false | [] | LowParse.Low.Combinators.serialize32_false | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | LowParse.Low.Base.serializer32 LowParse.Spec.Combinators.serialize_false | {
"end_col": 24,
"end_line": 470,
"start_col": 2,
"start_line": 470
} |
Prims.Tot | val validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: (unit -> Tot (parser k t)))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos | val validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: (unit -> Tot (parser k t)))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: (unit -> Tot (parser k t)))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"Prims.unit",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.Combinators.valid_lift_parser",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.lift_parser"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ())) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: (unit -> Tot (parser k t)))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p)) | [] | LowParse.Low.Combinators.validate_lift_parser | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p: (_: Prims.unit -> LowParse.Spec.Base.parser k t) -> v: LowParse.Low.Base.validator (p ())
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.lift_parser p) | {
"end_col": 13,
"end_line": 497,
"start_col": 2,
"start_line": 494
} |
Prims.Tot | val gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` (clens_fst _ _))) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _ | val gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` (clens_fst _ _)))
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` (clens_fst _ _))) = | false | null | false | g `gaccessor_compose` (gaccessor_fst _ () _) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"FStar.Pervasives.Native.tuple2",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Base.Spec.gaccessor_compose",
"LowParse.Low.Combinators.clens_fst",
"LowParse.Low.Combinators.gaccessor_fst",
"LowParse.Low.Base.Spec.clens_compose"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` (clens_fst _ _))) | [] | LowParse.Low.Combinators.gaccessor_then_fst | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | g: LowParse.Low.Base.Spec.gaccessor p0 (LowParse.Spec.Combinators.nondep_then p1 p2) cl
-> LowParse.Low.Base.Spec.gaccessor p0
p1
(LowParse.Low.Base.Spec.clens_compose cl (LowParse.Low.Combinators.clens_fst t1 t2)) | {
"end_col": 44,
"end_line": 756,
"start_col": 2,
"start_line": 756
} |
FStar.Pervasives.Lemma | val gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma (gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input) | val gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma (gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma (gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input) = | false | null | true | reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.unit",
"LowParse.Bytes.bytes",
"FStar.Pervasives.reveal_opaque",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_fst",
"Prims.l_True",
"Prims.eq2",
"LowParse.Low.Combinators.gaccessor_fst'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma (gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input) | [] | LowParse.Low.Combinators.gaccessor_fst_eq | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k1 t1 ->
sq: Prims.squash Prims.unit ->
p2: LowParse.Spec.Base.parser k2 t2 ->
input: LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(ensures
LowParse.Low.Combinators.gaccessor_fst p1 sq p2 input ==
LowParse.Low.Combinators.gaccessor_fst' p1 sq p2 input) | {
"end_col": 64,
"end_line": 725,
"start_col": 2,
"start_line": 725
} |
Prims.Ghost | val gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0 | val gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos')) = | false | null | false | parse_synth_eq p1 f input;
0 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.unit",
"Prims.l_and",
"LowParse.Spec.Combinators.synth_inverse",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Bytes.bytes",
"LowParse.Spec.Combinators.parse_synth_eq",
"Prims.nat",
"Prims.l_True",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Spec.Combinators.parse_synth",
"LowParse.Low.Combinators.clens_synth_inv"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: (t1 -> GTot t2))
(g: (t2 -> GTot t1))
(u: unit{synth_inverse f g /\ synth_injective f})
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos')) | [] | LowParse.Low.Combinators.gaccessor_synth_inv' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f: (_: t1 -> Prims.GTot t2) ->
g: (_: t2 -> Prims.GTot t1) ->
u225:
u229:
Prims.unit
{LowParse.Spec.Combinators.synth_inverse f g /\ LowParse.Spec.Combinators.synth_injective f} ->
input: LowParse.Bytes.bytes
-> Prims.Ghost Prims.nat | {
"end_col": 3,
"end_line": 614,
"start_col": 2,
"start_line": 613
} |
Prims.Tot | val gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2 | val gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _)) = | false | null | false | Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Combinators.gaccessor_snd'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Combinators.clens_snd",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.nat",
"FStar.Classical.move_requires",
"LowParse.Low.Combinators.gaccessor_snd_no_lookahead",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.Combinators.gaccessor_snd_injective",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _)) | [] | LowParse.Low.Combinators.gaccessor_snd | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p1: LowParse.Spec.Base.parser k1 t1 -> p2: LowParse.Spec.Base.parser k2 t2
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Combinators.nondep_then p1 p2)
p2
(LowParse.Low.Combinators.clens_snd t1 t2) | {
"end_col": 22,
"end_line": 818,
"start_col": 2,
"start_line": 815
} |
FStar.Pervasives.Lemma | val gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl' | val gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl')) = | false | null | true | nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl' | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_injective",
"Prims.unit",
"LowParse.Spec.Combinators.nondep_then_eq",
"Prims.l_and",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Combinators.clens_snd",
"LowParse.Spec.Base.injective_precond",
"Prims.squash",
"Prims.eq2",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_snd'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl')) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
(gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl')) | [] | LowParse.Low.Combinators.gaccessor_snd_injective | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k1 t1 ->
p2: LowParse.Spec.Base.parser k2 t2 ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.nondep_then p1 p2)
p2
(LowParse.Low.Combinators.clens_snd t1 t2)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.nondep_then p1 p2)
p2
(LowParse.Low.Combinators.clens_snd t1 t2)
sl /\
LowParse.Spec.Base.injective_precond (LowParse.Spec.Combinators.nondep_then p1 p2) sl sl')
(ensures
LowParse.Low.Combinators.gaccessor_snd' p1 p2 sl ==
LowParse.Low.Combinators.gaccessor_snd' p1 p2 sl') | {
"end_col": 27,
"end_line": 787,
"start_col": 2,
"start_line": 785
} |
Prims.Tot | val accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) () | val accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g)) = | false | null | false | accessor_compose a (accessor_fst p1 () p2) () | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.Spec.clens",
"FStar.Pervasives.Native.tuple2",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Base.accessor",
"LowParse.Low.Base.accessor_compose",
"LowParse.Low.Combinators.clens_fst",
"LowParse.Low.Combinators.gaccessor_fst",
"LowParse.Low.Combinators.accessor_fst",
"LowParse.Low.Base.Spec.clens_compose",
"LowParse.Low.Combinators.gaccessor_then_fst"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g)) | [] | LowParse.Low.Combinators.accessor_then_fst | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | a: LowParse.Low.Base.accessor g
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_then_fst g) | {
"end_col": 47,
"end_line": 922,
"start_col": 2,
"start_line": 922
} |
Prims.Tot | val write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res | val write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f)) = | false | null | false | fun x #rrel #rel input pos ->
[@@ inline_let ]let _ = serialized_length_eq s x in
[@@ inline_let ]let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h p f input pos in
res | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.leaf_writer_weak",
"Prims.bool",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Combinators.valid_filter",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.Spec.serialized_length_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.Combinators.serialize_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f)) | [] | LowParse.Low.Combinators.write_filter_weak | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s32: LowParse.Low.Base.leaf_writer_weak s -> f: (_: t -> Prims.GTot Prims.bool)
-> LowParse.Low.Base.leaf_writer_weak (LowParse.Spec.Combinators.serialize_filter s f) | {
"end_col": 5,
"end_line": 1139,
"start_col": 2,
"start_line": 1133
} |
Prims.Tot | val accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res | val accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2)) = | false | null | false | reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Combinators.clens_snd",
"LowParse.Low.Combinators.gaccessor_snd",
"LowParse.Low.Combinators.valid_nondep_then",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"FStar.Pervasives.reveal_opaque",
"LowParse.Low.Base.Spec.gaccessor",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2)) | [] | LowParse.Low.Combinators.accessor_snd | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | j1: LowParse.Low.Base.jumper p1 -> p2: LowParse.Spec.Base.parser k2 t2
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_snd p1 p2) | {
"end_col": 5,
"end_line": 943,
"start_col": 2,
"start_line": 934
} |
Prims.Tot | val read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) | val read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t{f res == true})) | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.leaf_reader",
"Prims.bool",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.eq2",
"Prims.unit",
"LowParse.Low.Combinators.valid_filter",
"LowParse.Spec.Combinators.parse_filter_refine",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f)) | [] | LowParse.Low.Combinators.read_filter | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | p32: LowParse.Low.Base.leaf_reader p -> f: (_: t -> Prims.GTot Prims.bool)
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.Combinators.parse_filter p f) | {
"end_col": 48,
"end_line": 1105,
"start_col": 2,
"start_line": 1102
} |
Prims.Tot | val serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos | val serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f)) = | false | null | false | fun x #rrel #rel input pos -> s32 x input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.serializer",
"LowParse.Low.Base.serializer32",
"Prims.bool",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowStar.Monotonic.Buffer.srel",
"LowParse.Bytes.byte",
"LowStar.Monotonic.Buffer.mbuffer",
"FStar.UInt32.t",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.Combinators.serialize_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f)) | [] | LowParse.Low.Combinators.serialize32_filter | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | s32: LowParse.Low.Base.serializer32 s -> f: (_: t -> Prims.GTot Prims.bool)
-> LowParse.Low.Base.serializer32 (LowParse.Spec.Combinators.serialize_filter s f) | {
"end_col": 17,
"end_line": 1151,
"start_col": 2,
"start_line": 1150
} |
Prims.Tot | val validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter p f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res | val validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter p f))
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter p f)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va) then validator_error_generic else res | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Low.Base.leaf_reader",
"Prims.bool",
"Prims.eq2",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"Prims.op_Negation",
"LowParse.Low.ErrorCode.validator_error_generic",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"Prims.unit",
"LowParse.Low.Combinators.valid_filter",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } ))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter p f)) | [] | LowParse.Low.Combinators.validate_filter | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
v32: LowParse.Low.Base.validator p ->
p32: LowParse.Low.Base.leaf_reader p ->
f: (_: t -> Prims.GTot Prims.bool) ->
f': (x: t -> y: Prims.bool{y == f x})
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_filter p f) | {
"end_col": 12,
"end_line": 1025,
"start_col": 2,
"start_line": 1015
} |
Prims.Tot | val read_inline_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' () | val read_inline_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2))
let read_inline_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) = | false | null | false | read_inline_synth p1 f2 (fun x -> f2 x) p1' () | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.leaf_reader",
"Prims.unit",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Low.Combinators.read_inline_synth",
"Prims.eq2",
"LowParse.Spec.Combinators.parse_synth"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
}) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_inline_synth'
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> Tot t2))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) | [] | LowParse.Low.Combinators.read_inline_synth' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f2: (_: t1 -> t2) ->
p1': LowParse.Low.Base.leaf_reader p1 ->
u478: u480: Prims.unit{LowParse.Spec.Combinators.synth_injective f2}
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.Combinators.parse_synth p1 f2) | {
"end_col": 48,
"end_line": 1217,
"start_col": 2,
"start_line": 1217
} |
Prims.Tot | val gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p | val gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data)) = | false | null | false | gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p)
pt
(clens_tagged_union_tag tag_of_data)
(gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Low.Combinators.gaccessor_tagged_union_tag'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Low.Combinators.clens_tagged_union_tag",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data)) | [] | LowParse.Low.Combinators.gaccessor_tagged_union_tag | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t))
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Combinators.parse_tagged_union pt tag_of_data p
)
pt
(LowParse.Low.Combinators.clens_tagged_union_tag tag_of_data) | {
"end_col": 46,
"end_line": 1431,
"start_col": 2,
"start_line": 1430
} |
FStar.Pervasives.Lemma | val gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl' | val gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl')) = | false | null | true | nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl';
parse_strong_prefix p1 sl sl' | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"lemma"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse_strong_prefix",
"Prims.unit",
"LowParse.Spec.Base.parse_injective",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Spec.Combinators.nondep_then_eq",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Low.Combinators.clens_snd",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.squash",
"Prims.nat",
"LowParse.Low.Combinators.gaccessor_snd'",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl')) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl': bytes)
: Lemma
(requires
((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\
no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl')) | [] | LowParse.Low.Combinators.gaccessor_snd_no_lookahead | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k1 t1 ->
p2: LowParse.Spec.Base.parser k2 t2 ->
sl: LowParse.Bytes.bytes ->
sl': LowParse.Bytes.bytes
-> FStar.Pervasives.Lemma
(requires
Mkparser_kind'?.parser_kind_subkind (LowParse.Spec.Combinators.and_then_kind k1 k2) ==
FStar.Pervasives.Native.Some LowParse.Spec.Base.ParserStrong /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.nondep_then p1 p2)
p2
(LowParse.Low.Combinators.clens_snd t1 t2)
sl /\
LowParse.Low.Base.Spec.gaccessor_pre (LowParse.Spec.Combinators.nondep_then p1 p2)
p2
(LowParse.Low.Combinators.clens_snd t1 t2)
sl /\
LowParse.Spec.Base.no_lookahead_on_precond (LowParse.Spec.Combinators.nondep_then p1 p2)
sl
sl')
(ensures
LowParse.Low.Combinators.gaccessor_snd' p1 p2 sl ==
LowParse.Low.Combinators.gaccessor_snd' p1 p2 sl') | {
"end_col": 31,
"end_line": 804,
"start_col": 2,
"start_line": 800
} |
Prims.Tot | val jump_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos | val jump_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
let jump_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_facts (weaken k1 p2) h input pos in
[@@ inline_let ]let _ = valid_facts p2 h input pos in
v2 input pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.jumper",
"Prims.squash",
"LowParse.Spec.Base.is_weaker_than",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Base.weaken",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val jump_weaken
(k1 #k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2)) | [] | LowParse.Low.Combinators.jump_weaken | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
k1: LowParse.Spec.Base.parser_kind ->
v2: LowParse.Low.Base.jumper p2 ->
sq: Prims.squash (LowParse.Spec.Base.is_weaker_than k1 k2)
-> LowParse.Low.Base.jumper (LowParse.Spec.Base.weaken k1 p2) | {
"end_col": 14,
"end_line": 1355,
"start_col": 2,
"start_line": 1349
} |
Prims.Ghost | val gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos')) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0 | val gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos')) = | false | null | false | nondep_then_eq p1 p2 input;
0 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.squash",
"Prims.unit",
"LowParse.Bytes.bytes",
"LowParse.Spec.Combinators.nondep_then_eq",
"Prims.nat",
"Prims.l_True",
"LowParse.Low.Base.Spec.gaccessor_post'",
"LowParse.Spec.Combinators.and_then_kind",
"FStar.Pervasives.Native.tuple2",
"LowParse.Spec.Combinators.nondep_then",
"LowParse.Low.Combinators.clens_fst"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos')) | [] | LowParse.Low.Combinators.gaccessor_fst' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k1 t1 ->
sq: Prims.squash Prims.unit ->
p2: LowParse.Spec.Base.parser k2 t2 ->
input: LowParse.Bytes.bytes
-> Prims.Ghost Prims.nat | {
"end_col": 3,
"end_line": 699,
"start_col": 2,
"start_line": 698
} |
Prims.Tot | val validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter (parse_ret r) f)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos | val validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter (parse_ret r) f))
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter (parse_ret r) f)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@@ inline_let ]let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r) then validator_error_generic else pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"Prims.bool",
"Prims.eq2",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"Prims.op_Negation",
"LowParse.Low.ErrorCode.validator_error_generic",
"Prims.unit",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Spec.Combinators.parse_ret_kind",
"LowParse.Spec.Combinators.parse_ret",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.Combinators.valid_filter",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.validator",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } ))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f': (x: t -> Tot (y: bool{y == f x})))
: Tot (validator (parse_filter (parse_ret r) f)) | [] | LowParse.Low.Combinators.validate_filter_ret | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | r: t -> f: (_: t -> Prims.GTot Prims.bool) -> f': (x: t -> y: Prims.bool{y == f x})
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.parse_filter (LowParse.Spec.Combinators.parse_ret
r)
f) | {
"end_col": 10,
"end_line": 1063,
"start_col": 2,
"start_line": 1057
} |
Prims.Tot | val clens_tagged_union_payload
(#tag_t #data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
= {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t));
} | val clens_tagged_union_payload
(#tag_t #data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
let clens_tagged_union_payload
(#tag_t #data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t)) = | false | null | false | {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t))
} | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Low.Base.Spec.Mkclens",
"LowParse.Spec.Base.refine_with_tag",
"Prims.eq2",
"LowParse.Low.Base.Spec.clens"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos
let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t)) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val clens_tagged_union_payload
(#tag_t #data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t)) | [] | LowParse.Low.Combinators.clens_tagged_union_payload | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | tag_of_data: (_: data_t -> Prims.GTot tag_t) -> t: tag_t
-> LowParse.Low.Base.Spec.clens data_t (LowParse.Spec.Base.refine_with_tag tag_of_data t) | {
"end_col": 75,
"end_line": 1456,
"start_col": 4,
"start_line": 1455
} |
Prims.Tot | val read_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(f2': (x: t1 -> Tot (y: t2{y == f2 x})))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 | val read_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(f2': (x: t1 -> Tot (y: t2{y == f2 x})))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2))
let read_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(f2': (x: t1 -> Tot (y: t2{y == f2 x})))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"Prims.eq2",
"LowParse.Low.Base.leaf_reader",
"Prims.unit",
"LowParse.Spec.Combinators.synth_injective",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"LowParse.Low.Combinators.valid_synth",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Spec.Combinators.parse_synth"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
}) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val read_synth
(#k: parser_kind)
(#t1 #t2: Type)
(p1: parser k t1)
(f2: (t1 -> GTot t2))
(f2': (x: t1 -> Tot (y: t2{y == f2 x})))
(p1': leaf_reader p1)
(u: unit{synth_injective f2})
: Tot (leaf_reader (parse_synth p1 f2)) | [] | LowParse.Low.Combinators.read_synth | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
p1: LowParse.Spec.Base.parser k t1 ->
f2: (_: t1 -> Prims.GTot t2) ->
f2': (x: t1 -> y: t2{y == f2 x}) ->
p1': LowParse.Low.Base.leaf_reader p1 ->
u457: u461: Prims.unit{LowParse.Spec.Combinators.synth_injective f2}
-> LowParse.Low.Base.leaf_reader (LowParse.Spec.Combinators.parse_synth p1 f2) | {
"end_col": 15,
"end_line": 1170,
"start_col": 2,
"start_line": 1166
} |
Prims.Tot | val gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_tagged_union_payload_injective pt tag_of_data p t x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_tagged_union_payload_no_lookahead pt tag_of_data p t x));
gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) (gaccessor_tagged_union_payload' pt tag_of_data p t);
gaccessor_tagged_union_payload' pt tag_of_data p t | val gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t))
let gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)) = | false | null | false | Classical.forall_intro_2 (fun x ->
Classical.move_requires (gaccessor_tagged_union_payload_injective pt tag_of_data p t x));
Classical.forall_intro_2 (fun x ->
Classical.move_requires (gaccessor_tagged_union_payload_no_lookahead pt tag_of_data p t x));
gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)
(gaccessor_tagged_union_payload' pt tag_of_data p t);
gaccessor_tagged_union_payload' pt tag_of_data p t | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Low.Combinators.gaccessor_tagged_union_payload'",
"Prims.unit",
"LowParse.Low.Base.Spec.gaccessor_prop_equiv",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Low.Combinators.clens_tagged_union_payload",
"FStar.Classical.forall_intro_2",
"LowParse.Bytes.bytes",
"Prims.l_imp",
"Prims.l_and",
"Prims.eq2",
"FStar.Pervasives.Native.option",
"LowParse.Spec.Base.parser_subkind",
"LowParse.Spec.Base.__proj__Mkparser_kind'__item__parser_kind_subkind",
"FStar.Pervasives.Native.Some",
"LowParse.Spec.Base.ParserStrong",
"LowParse.Low.Base.Spec.gaccessor_pre",
"LowParse.Spec.Base.no_lookahead_on_precond",
"Prims.nat",
"FStar.Classical.move_requires",
"LowParse.Low.Combinators.gaccessor_tagged_union_payload_no_lookahead",
"Prims.l_True",
"Prims.squash",
"Prims.Nil",
"FStar.Pervasives.pattern",
"LowParse.Spec.Base.injective_precond",
"LowParse.Low.Combinators.gaccessor_tagged_union_payload_injective",
"LowParse.Low.Base.Spec.gaccessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos
let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
= {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t));
}
let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
match parse pt input with
| Some (t', consumed_t) ->
consumed_t
| _ -> 0 (* dummy *)
let gaccessor_tagged_union_payload_injective
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
injective_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_injective (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl'
let gaccessor_tagged_union_payload_no_lookahead
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
(sl sl' : bytes)
: Lemma
(requires (
(and_then_kind kt k).parser_kind_subkind == Some ParserStrong /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl /\
gaccessor_pre (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t) sl' /\
no_lookahead_on_precond (parse_tagged_union pt tag_of_data p) sl sl'
))
(ensures (
gaccessor_tagged_union_payload' pt tag_of_data p t sl == gaccessor_tagged_union_payload' pt tag_of_data p t sl'
))
= parse_strong_prefix (parse_tagged_union pt tag_of_data p) sl sl' ;
parse_tagged_union_eq pt tag_of_data p sl ;
parse_tagged_union_eq pt tag_of_data p sl' ;
parse_injective pt sl sl'
let gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_tagged_union_payload
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)) | [] | LowParse.Low.Combinators.gaccessor_tagged_union_payload | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t)) ->
t: tag_t
-> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Combinators.parse_tagged_union pt tag_of_data p
)
(p t)
(LowParse.Low.Combinators.clens_tagged_union_payload tag_of_data t) | {
"end_col": 52,
"end_line": 1538,
"start_col": 2,
"start_line": 1535
} |
Prims.Tot | val gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor' (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t)
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) (p t) (clens_tagged_union_payload tag_of_data t))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
match parse pt input with
| Some (t', consumed_t) ->
consumed_t
| _ -> 0 | val gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor' (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t))
let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor' (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)) = | false | null | false | fun input ->
parse_tagged_union_eq pt tag_of_data p input;
match parse pt input with
| Some (t', consumed_t) -> consumed_t
| _ -> 0 | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Bytes.bytes",
"LowParse.Spec.Base.parse",
"LowParse.Spec.Base.consumed_length",
"FStar.Pervasives.Native.option",
"FStar.Pervasives.Native.tuple2",
"Prims.nat",
"Prims.unit",
"LowParse.Spec.Combinators.parse_tagged_union_eq",
"LowParse.Low.Base.Spec.gaccessor'",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Low.Combinators.clens_tagged_union_payload"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos
let clens_tagged_union_payload
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(t: tag_t)
: Tot (clens data_t (refine_with_tag tag_of_data t))
= {
clens_cond = (fun d -> tag_of_data d == t);
clens_get = (fun (d: data_t) -> (d <: refine_with_tag tag_of_data t));
}
let gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
(t: tag_t) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val gaccessor_tagged_union_payload'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
(t: tag_t)
: Tot
(gaccessor' (parse_tagged_union pt tag_of_data p)
(p t)
(clens_tagged_union_payload tag_of_data t)) | [] | LowParse.Low.Combinators.gaccessor_tagged_union_payload' | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t)) ->
t: tag_t
-> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Combinators.parse_tagged_union pt
tag_of_data
p)
(p t)
(LowParse.Low.Combinators.clens_tagged_union_payload tag_of_data t) | {
"end_col": 14,
"end_line": 1474,
"start_col": 2,
"start_line": 1469
} |
Prims.Tot | val accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos in
pos | val accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p))
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
slice_access_eq h (gaccessor_tagged_union_tag pt tag_of_data p) input pos
in
pos | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Spec.Base.refine_with_tag",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt32.t",
"Prims.unit",
"LowParse.Low.Base.Spec.slice_access_eq",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.parse_tagged_union",
"LowParse.Low.Combinators.clens_tagged_union_tag",
"LowParse.Low.Combinators.gaccessor_tagged_union_tag",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get",
"LowParse.Low.Base.accessor"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic
inline_for_extraction
let validate_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: validator p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (validator (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p2 h input (uint64_to_uint32 pos) in
v2 input pos
inline_for_extraction
let jump_weaken
(k1: parser_kind)
(#k2: parser_kind)
(#t: Type)
(#p2: parser k2 t)
(v2: jumper p2)
(sq: squash (k1 `is_weaker_than` k2))
: Tot (jumper (weaken k1 p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (weaken k1 p2) h input pos in
[@inline_let]
let _ = valid_facts p2 h input pos in
v2 input pos
inline_for_extraction
let validate_strengthen
(k2: parser_kind)
(#k1: parser_kind)
(#t: Type)
(#p1: parser k1 t)
(v1: validator p1)
(sq: squash (parser_kind_prop k2 p1))
: Tot (validator (strengthen k2 p1))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts (strengthen k2 p1) h input (uint64_to_uint32 pos) in
[@inline_let]
let _ = valid_facts p1 h input (uint64_to_uint32 pos) in
v1 input pos
inline_for_extraction
let validate_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (validator (p k))))
(k: kt2)
: Tot (validator (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
inline_for_extraction
let jump_compose_context
(#pk: parser_kind)
(#kt1 #kt2: Type)
(f: (kt2 -> Tot kt1))
(t: (kt1 -> Tot Type))
(p: ((k: kt1) -> Tot (parser pk (t k))))
(v: ((k: kt1) -> Tot (jumper (p k))))
(k: kt2)
: Tot (jumper (p (f k)))
= fun #rrel #rel input pos -> v (f k) input pos
let clens_tagged_union_tag
(#tag_t: Type)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
: Tot (clens data_t tag_t)
= {
clens_cond = (fun _ -> True);
clens_get = tag_of_data;
}
let gaccessor_tagged_union_tag'
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor' (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= fun input ->
parse_tagged_union_eq pt tag_of_data p input;
0
let gaccessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t)))
: Tot (gaccessor (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data))
= gaccessor_prop_equiv (parse_tagged_union pt tag_of_data p) pt (clens_tagged_union_tag tag_of_data) (gaccessor_tagged_union_tag' pt tag_of_data p);
gaccessor_tagged_union_tag' pt tag_of_data p
inline_for_extraction
let accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t) -> Tot (parser k (refine_with_tag tag_of_data t))) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val accessor_tagged_union_tag
(#kt: parser_kind)
(#tag_t: Type)
(pt: parser kt tag_t)
(#data_t: Type)
(tag_of_data: (data_t -> GTot tag_t))
(#k: parser_kind)
(p: (t: tag_t -> Tot (parser k (refine_with_tag tag_of_data t))))
: Tot (accessor (gaccessor_tagged_union_tag pt tag_of_data p)) | [] | LowParse.Low.Combinators.accessor_tagged_union_tag | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
pt: LowParse.Spec.Base.parser kt tag_t ->
tag_of_data: (_: data_t -> Prims.GTot tag_t) ->
p: (t: tag_t -> LowParse.Spec.Base.parser k (LowParse.Spec.Base.refine_with_tag tag_of_data t))
-> LowParse.Low.Base.accessor (LowParse.Low.Combinators.gaccessor_tagged_union_tag pt
tag_of_data
p) | {
"end_col": 5,
"end_line": 1446,
"start_col": 2,
"start_line": 1443
} |
Prims.Tot | val validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f': (x: t1 -> Tot (y: bool{y == f x})))
(#k2: parser_kind)
(#t2: Type)
(#p2: (x: t1{f x == true} -> parser k2 t2))
(v2: (x1: t1{f x1 == true} -> validator (p2 x1)))
(u: unit{and_then_cases_injective p2})
: Tot (validator ((parse_filter p1 f) `and_then` p2)) | [
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "HST"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "FStar.UInt32",
"short_module": "U32"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B0"
},
{
"abbrev": true,
"full_module": "LowStar.Monotonic.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "LowParse.Spec.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
})
: Tot (validator (parse_filter p1 f `and_then` p2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts (parse_filter p1 f `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@inline_let]
let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic | val validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f': (x: t1 -> Tot (y: bool{y == f x})))
(#k2: parser_kind)
(#t2: Type)
(#p2: (x: t1{f x == true} -> parser k2 t2))
(v2: (x1: t1{f x1 == true} -> validator (p2 x1)))
(u: unit{and_then_cases_injective p2})
: Tot (validator ((parse_filter p1 f) `and_then` p2))
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f': (x: t1 -> Tot (y: bool{y == f x})))
(#k2: parser_kind)
(#t2: Type)
(#p2: (x: t1{f x == true} -> parser k2 t2))
(v2: (x1: t1{f x1 == true} -> validator (p2 x1)))
(u: unit{and_then_cases_injective p2})
: Tot (validator ((parse_filter p1 f) `and_then` p2)) = | false | null | false | fun #rrel #rel input pos ->
let h = HST.get () in
[@@ inline_let ]let _ =
let sinput = bytes_of_slice_from h input (uint64_to_uint32 pos) in
valid_facts ((parse_filter p1 f) `and_then` p2) h input (uint64_to_uint32 pos);
and_then_eq (parse_filter p1 f) p2 sinput;
parse_filter_eq p1 f sinput;
valid_facts p1 h input (uint64_to_uint32 pos)
in
let res = v1 input pos in
if is_error res
then res
else
let va = p1' input (uint64_to_uint32 pos) in
if f' va
then
[@@ inline_let ]let _ = valid_facts (p2 va) h input (uint64_to_uint32 res) in
v2 va input res
else validator_error_generic | {
"checked_file": "LowParse.Low.Combinators.fsti.checked",
"dependencies": [
"prims.fst.checked",
"LowStar.Monotonic.Buffer.fsti.checked",
"LowStar.Failure.fsti.checked",
"LowStar.Buffer.fst.checked",
"LowParse.Spec.Combinators.fsti.checked",
"LowParse.Low.Base.fst.checked",
"FStar.UInt64.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Seq.fst.checked",
"FStar.Pervasives.Native.fst.checked",
"FStar.Pervasives.fsti.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked",
"FStar.Ghost.fsti.checked",
"FStar.Classical.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.Combinators.fsti"
} | [
"total"
] | [
"LowParse.Spec.Base.parser_kind",
"LowParse.Spec.Base.parser",
"LowParse.Low.Base.validator",
"LowParse.Low.Base.leaf_reader",
"Prims.bool",
"Prims.eq2",
"Prims.unit",
"LowParse.Spec.Combinators.and_then_cases_injective",
"LowParse.Slice.srel",
"LowParse.Bytes.byte",
"LowParse.Slice.slice",
"FStar.UInt64.t",
"LowParse.Low.ErrorCode.is_error",
"LowParse.Low.Base.Spec.valid_facts",
"LowParse.Low.ErrorCode.uint64_to_uint32",
"LowParse.Low.ErrorCode.validator_error_generic",
"LowParse.Spec.Combinators.parse_filter_eq",
"LowParse.Spec.Combinators.and_then_eq",
"LowParse.Spec.Combinators.parse_filter_kind",
"LowParse.Spec.Combinators.parse_filter_refine",
"LowParse.Spec.Combinators.parse_filter",
"LowParse.Spec.Combinators.and_then_kind",
"LowParse.Spec.Combinators.and_then",
"LowParse.Bytes.bytes",
"LowParse.Slice.bytes_of_slice_from",
"FStar.Monotonic.HyperStack.mem",
"FStar.HyperStack.ST.get"
] | [] | module LowParse.Low.Combinators
include LowParse.Low.Base
include LowParse.Spec.Combinators
module B = LowStar.Monotonic.Buffer
module B0 = LowStar.Buffer
module U32 = FStar.UInt32
module HS = FStar.HyperStack
module HST = FStar.HyperStack.ST
#set-options "--z3rlimit 16"
let valid_nondep_then
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (nondep_then p1 p2) h s pos \/
(valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
valid p2 h s (get_valid_pos p1 h s pos) /\
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (nondep_then p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
nondep_then_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
valid_facts p2 h s pos1
end
end
let valid_nondep_then_intro
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (valid p1 h s pos /\ valid p2 h s (get_valid_pos p1 h s pos)))
(ensures ((
let pos1 = get_valid_pos p1 h s pos in
valid_content_pos (nondep_then p1 p2) h s pos (contents p1 h s pos, contents p2 h s pos1) (get_valid_pos p2 h s pos1)
)))
= valid_nondep_then h p1 p2 s pos
inline_for_extraction
let validate_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : validator p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : validator p2)
: Tot (validator (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = p1' input pos in
if is_error pos1
then begin
pos1
end
else
[@inline_let] let _ = valid_facts p2 h input (uint64_to_uint32 pos1) in
p2' input pos1
inline_for_extraction
let jump_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(p2' : jumper p2)
: Tot (jumper (nondep_then p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
p2' input (p1' input pos)
inline_for_extraction
let read_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(p1' : jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(r2: leaf_reader p2)
: Tot (leaf_reader (nondep_then p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = p1' sl pos in
let x2 = r2 sl pos2 in
(x1, x2)
inline_for_extraction
let serialize32_nondep_then_aux
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
(x1: t1)
(x2: t2)
(#rrel: _) (#rel: _)
(b: B.mbuffer byte rrel rel)
(pos: U32.t)
: HST.Stack U32.t
(requires (fun h ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
let len = len1 + len2 in
let sq = B.as_seq h b in
B.live h b /\
U32.v pos + len <= B.length b /\
writable b (U32.v pos) (U32.v pos + len) h
))
(ensures (fun h len h' ->
let len1 = Seq.length (serialize s1 x1) in
let len2 = Seq.length (serialize s2 x2) in
len1 + len2 == U32.v len /\ (
B.modifies (B.loc_buffer_from_to b pos (pos `U32.add` len)) h h' /\
B.live h b /\
Seq.slice (B.as_seq h' b) (U32.v pos) (U32.v pos + U32.v len) `Seq.equal` (serialize s1 x1 `Seq.append` serialize s2 x2)
)))
=
let gpos' = Ghost.hide (pos `U32.add` U32.uint_to_t (Seq.length (serialize s1 x1) + Seq.length (serialize s2 x2))) in
let len1 = frame_serializer32 s1' x1 b (Ghost.hide pos) gpos' pos in
let pos1 = pos `U32.add` len1 in
let len2 = frame_serializer32 s2' x2 b (Ghost.hide pos) gpos' pos1 in
let h1 = HST.get () in
len1 `U32.add` len2
inline_for_extraction
let serialize32_nondep_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong })
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#s2: serializer p2)
(s2' : serializer32 s2)
: Tot (serializer32 (s1 `serialize_nondep_then` s2))
= fun x #rrel #rel b pos ->
[@inline_let]
let (x1, x2) = x in
serialize_nondep_then_eq s1 s2 x;
serialize32_nondep_then_aux s1' s2' x1 x2 b pos
let valid_synth
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
live_slice h input /\ synth_injective f2
))
(ensures (
(valid (parse_synth p1 f2) h input pos \/ valid p1 h input pos) ==> (
valid p1 h input pos /\
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
)))
= valid_facts p1 h input pos;
valid_facts (parse_synth p1 f2) h input pos;
if U32.v pos <= U32.v input.len
then parse_synth_eq p1 f2 (bytes_of_slice_from h input pos)
let valid_synth_intro
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (
synth_injective f2 /\
valid p1 h input pos
))
(ensures (
valid_content_pos (parse_synth p1 f2) h input pos (f2 (contents p1 h input pos)) (get_valid_pos p1 h input pos)
))
= valid_synth h p1 f2 input pos
inline_for_extraction
let validate_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : validator p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (validator (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input (uint64_to_uint32 pos) in
p1' input pos
inline_for_extraction
let jump_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(#p1: parser k t1)
(p1' : jumper p1)
(f2: t1 -> GTot t2)
(u: unit {
synth_injective f2
})
: Tot (jumper (parse_synth p1 f2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
p1' input pos
let valid_dtuple2
(#rrel #rel: _)
(h: HS.mem)
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(s: slice rrel rel)
(pos: U32.t)
: Lemma
(requires (live_slice h s))
(ensures ((
valid (parse_dtuple2 p1 p2) h s pos \/
(valid p1 h s pos /\ valid (p2 (contents p1 h s pos)) h s (get_valid_pos p1 h s pos))
) ==> (
valid p1 h s pos /\ (
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid (p2 x) h s (get_valid_pos p1 h s pos) /\
valid_content_pos (parse_dtuple2 p1 p2) h s pos (| x, contents (p2 x) h s pos1 |) (get_valid_pos (p2 x) h s pos1)
))))
= valid_facts p1 h s pos;
valid_facts (parse_dtuple2 p1 p2) h s pos;
if U32.v pos <= U32.v s.len
then begin
parse_dtuple2_eq p1 p2 (bytes_of_slice_from h s pos);
if valid_dec p1 h s pos
then begin
let pos1 = get_valid_pos p1 h s pos in
let x = contents p1 h s pos in
valid_facts (p2 x) h s pos1
end
end
inline_for_extraction
let validate_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (validator (p2 x)))
: Tot (validator (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input (uint64_to_uint32 pos) in
let pos1 = v1 input pos in
if is_error pos1
then begin
pos1
end
else
let x = r1 input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (p2 x) h input (uint64_to_uint32 pos1) in
v2 x input pos1
inline_for_extraction
let jump_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(v2: (x: t1) -> Tot (jumper (p2 x)))
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
let x = r1 input pos in
[@inline_let] let _ = valid_facts (p2 x) h input pos1 in
v2 x input pos1
inline_for_extraction
let jump_dtuple2_constant_size_dsnd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(p2: (x: t1) -> parser k2 (t2 x))
(sz: U32.t { U32.v sz == k2.parser_kind_low /\ k2.parser_kind_high == Some k2.parser_kind_low })
: Tot (jumper (parse_dtuple2 p1 p2))
= fun (#rrel #rel: _)
(input: slice rrel rel) (pos: U32.t) ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 input pos in
let pos1 = v1 input pos in
[@inline_let] let p2x = Ghost.hide (p2 (contents p1 h input pos)) in
[@inline_let] let _ = valid_facts (Ghost.reveal p2x) h input pos1 in
jump_constant_size' (fun _ -> Ghost.reveal p2x) sz () input pos1
inline_for_extraction
let read_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: jumper p1)
(r1: leaf_reader p1)
(#k2: parser_kind)
(#t2: t1 -> Type)
(#p2: (x: t1) -> parser k2 (t2 x))
(r2: (x: t1) -> Tot (leaf_reader (p2 x)))
: Tot (leaf_reader (parse_dtuple2 p1 p2))
= fun #_ #_ sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_dtuple2 h p1 p2 sl pos in
let x1 = r1 sl pos in
let pos2 = v1 sl pos in
let x2 = r2 x1 sl pos2 in
(| x1, x2 |)
inline_for_extraction
let serialize32_dtuple2
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#s1: serializer p1)
(s1' : serializer32 s1 { k1.parser_kind_subkind == Some ParserStrong } )
(#k2: parser_kind)
(#t2: t1 -> Tot Type)
(#p2: (x: t1) -> Tot (parser k2 (t2 x)))
(#s2: (x: t1) -> Tot (serializer (p2 x)))
(s2' : (x: t1) -> serializer32 (s2 x))
: Tot (serializer32 (serialize_dtuple2 s1 s2))
= fun (x: dtuple2 t1 t2) #_ #_ b pos ->
[@inline_let]
let _ = serialize_dtuple2_eq s1 s2 x in
match x with
| (| x1, x2 |) ->
serialize32_nondep_then_aux s1' (s2' x1) x1 x2 b pos
inline_for_extraction
let validate_ret
(#t: Type)
(v: t)
: Tot (validator (parse_ret v))
= validate_total_constant_size (parse_ret v) 0uL ()
inline_for_extraction
let validate_empty () : Tot (validator parse_empty)
= validate_ret ()
inline_for_extraction
let validate_false () : Tot (validator parse_false)
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let]
let _ = valid_facts parse_false h input (uint64_to_uint32 pos) in
validator_error_generic
inline_for_extraction
let jump_empty : jumper parse_empty
= jump_constant_size parse_empty 0ul ()
inline_for_extraction
let jump_false : jumper parse_false
= jump_constant_size parse_false 0ul ()
inline_for_extraction
let read_ret
(#t: Type)
(v: t)
: Tot (leaf_reader (parse_ret v))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (parse_ret v) h sl pos in
v
inline_for_extraction
let read_empty : leaf_reader parse_empty = read_ret ()
inline_for_extraction
let read_false : leaf_reader parse_false = fun #rrel #rel sl pos ->
LowStar.Failure.failwith "read_false: should not be called"
inline_for_extraction
let serialize32_ret
(#t: Type)
(v: t)
(v_unique: (v' : t) -> Lemma (v == v'))
: Tot (serializer32 (serialize_ret v v_unique))
= fun _ #_ #_ _ _ -> 0ul
inline_for_extraction
let serialize32_empty : serializer32 #_ #_ #parse_empty serialize_empty
= serialize32_ret () (fun _ -> ())
inline_for_extraction
let serialize32_false : serializer32 #_ #_ #parse_false serialize_false
= fun _ #_ #_ _ _ -> 0ul // dummy
let valid_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(h: HS.mem)
#rrel #rel
(input: slice rrel rel)
(pos: U32.t)
: Lemma
((valid (lift_parser p) h input pos \/ valid (p ()) h input pos) ==>
valid (p ()) h input pos /\
valid_content_pos (lift_parser p) h input pos (contents (p ()) h input pos) (get_valid_pos (p ()) h input pos))
= valid_facts (p ()) h input pos;
valid_facts (lift_parser p) h input pos
inline_for_extraction
let validate_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: validator #k #t (p ()))
: Tot (validator #k #t (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input (uint64_to_uint32 pos);
v input pos
inline_for_extraction
let jump_lift_parser
(#k: parser_kind)
(#t: Type)
(p: unit -> Tot (parser k t))
(v: jumper (p ()))
: Tot (jumper (lift_parser p))
= fun #rrel #rel input pos ->
let h = HST.get () in
valid_lift_parser p h input pos;
v input pos
let clens_synth
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t1 t2)
= {
clens_cond = (fun (x: t1) -> True);
clens_get = (fun (x: t1) -> f x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (parse_synth p1 f) p1 (clens_synth g f) input pos'))
= synth_injective_synth_inverse_synth_inverse_recip f g ();
parse_synth_eq p1 f input;
0
val gaccessor_synth
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor (parse_synth p1 f) p1 (clens_synth g f))
val gaccessor_synth_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth p1 f g u input == gaccessor_synth' p1 f g u input)
inline_for_extraction
let accessor_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_eq p1 f g u);
slice_access_eq h (gaccessor_synth p1 f g u) input pos
in
pos
let clens_synth_inv
(#t1: Type)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
: Tot (clens t2 t1)
= {
clens_cond = (fun (x: t2) -> True);
clens_get = (fun (x: t2) -> g x);
(*
clens_put = (fun (x: t1) (y: t2) -> g y);
clens_get_put = (fun (x: t1) (y: t2) -> ());
clens_put_put = (fun (x: t1) (y y' : t2) -> ());
clens_put_get = (fun (x: t1) -> ());
*)
}
let gaccessor_synth_inv'
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' p1 (parse_synth p1 f) (clens_synth_inv g f) input pos'))
= parse_synth_eq p1 f input;
0
val gaccessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: squash (synth_inverse f g /\ synth_injective f))
: Tot (gaccessor p1 (parse_synth p1 f) (clens_synth_inv g f))
val gaccessor_synth_inv_eq
(#k: parser_kind)
(#t1: Type)
(p1: parser k t1)
(#t2: Type)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
(input: bytes)
: Lemma
(gaccessor_synth_inv p1 f g u input == gaccessor_synth_inv' p1 f g u input)
inline_for_extraction
let accessor_synth_inv
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f: t1 -> GTot t2)
(g: t2 -> GTot t1)
(u: unit { synth_inverse f g /\ synth_injective f } )
: Tot (accessor (gaccessor_synth_inv p1 f g u))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ =
Classical.forall_intro (gaccessor_synth_inv_eq p1 f g u);
slice_access_eq h (gaccessor_synth_inv p1 f g u) input pos
in
pos
let clens_fst
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t1)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = fst;
(*
clens_put = (fun x y -> (y, snd x));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let clens_snd
(t1: Type)
(t2: Type)
: Tot (clens (t1 & t2) t2)
= {
clens_cond = (fun (x: (t1 & t2)) -> True);
clens_get = snd;
(*
clens_put = (fun x y -> (fst x, y));
clens_get_put = (fun x y -> ());
clens_put_put = (fun x y y' -> ());
clens_put_get = (fun x -> ());
*)
}
let gaccessor_fst'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires True)
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p1 (clens_fst _ _) input pos'))
= nondep_then_eq p1 p2 input;
0
[@"opaque_to_smt"]
let gaccessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p1 (clens_fst _ _))
= gaccessor_prop_equiv (p1 `nondep_then` p2) p1 (clens_fst _ _) (gaccessor_fst' p1 sq p2);
gaccessor_fst' p1 sq p2
let gaccessor_fst_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_fst p1 sq p2 input == gaccessor_fst' p1 sq p2 input)
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2 input)
let gaccessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(g: gaccessor p1 p' cl)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (gaccessor (p1 `nondep_then` p2) p' (clens_fst _ _ `clens_compose` cl))
= gaccessor_fst p1 u p2 `gaccessor_compose` g
let gaccessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p1 (cl `clens_compose` clens_fst _ _))
= g `gaccessor_compose` gaccessor_fst _ () _
let gaccessor_snd'
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Ghost (nat)
(requires (True))
(ensures (fun pos' -> gaccessor_post' (p1 `nondep_then` p2) p2 (clens_snd _ _) input pos'))
= nondep_then_eq p1 p2 input;
match parse p1 input with
| None -> 0 // dummy
| Some (_, consumed) -> consumed
let gaccessor_snd_injective
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires (gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ injective_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl';
parse_injective p1 sl sl'
let gaccessor_snd_no_lookahead
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(sl sl' : bytes)
: Lemma
(requires ((and_then_kind k1 k2).parser_kind_subkind == Some ParserStrong /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ gaccessor_pre (p1 `nondep_then` p2) p2 (clens_snd _ _) sl /\ no_lookahead_on_precond (p1 `nondep_then` p2) sl sl'))
(ensures (gaccessor_snd' p1 p2 sl == gaccessor_snd' p1 p2 sl'))
= nondep_then_eq p1 p2 sl;
nondep_then_eq p1 p2 sl' ;
parse_strong_prefix (p1 `nondep_then` p2) sl sl';
parse_injective p1 sl sl' ;
parse_strong_prefix p1 sl sl'
[@"opaque_to_smt"]
let gaccessor_snd
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (gaccessor (p1 `nondep_then` p2) p2 (clens_snd _ _))
= Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_injective p1 p2 x));
Classical.forall_intro_2 (fun x -> Classical.move_requires (gaccessor_snd_no_lookahead p1 p2 x));
gaccessor_prop_equiv (p1 `nondep_then` p2) p2 (clens_snd _ _) (gaccessor_snd' p1 p2);
gaccessor_snd' p1 p2
let gaccessor_snd_eq
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(input: bytes)
: Lemma
(gaccessor_snd p1 p2 input == gaccessor_snd' p1 p2 input)
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2 input )
let gaccessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(g: gaccessor p0 (p1 `nondep_then` p2) cl)
: Tot (gaccessor p0 p2 (cl `clens_compose` clens_snd _ _))
= g `gaccessor_compose` gaccessor_snd _ _
(*
let clens_fst_snd_disjoint
(t1 t2: Type)
: Lemma
(clens_disjoint (clens_fst t1 t2) (clens_snd t1 t2))
= clens_disjoint_l_intro (clens_fst t1 t2) (clens_snd t1 t2) (fun x1 x2 -> ());
clens_disjoint_l_intro (clens_snd t1 t2) (clens_fst t1 t2) (fun x1 x2 -> ())
*)
(*
abstract
let gaccessor_fst_snd_disjoint
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash (k1.parser_kind_subkind == Some ParserStrong))
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Lemma
(gaccessors_disjoint (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2))
= // clens_fst_snd_disjoint t1 t2;
gaccessors_disjoint_intro (gaccessor_fst p1 sq p2) (gaccessor_snd p1 p2) (* *) (fun x -> ())
*)
inline_for_extraction
let accessor_fst
(#k1: parser_kind)
(#t1: Type)
(p1: parser k1 t1)
(sq: squash unit)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_fst p1 sq p2))
= reveal_opaque (`%gaccessor_fst) (gaccessor_fst p1 sq p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = slice_access_eq h (gaccessor_fst p1 sq p2) input pos in
pos
inline_for_extraction
let accessor_fst_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k' : parser_kind)
(#t' : Type)
(#p': parser k' t')
(#cl: clens t1 t')
(#g: gaccessor p1 p' cl)
(a: accessor g)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
(u: squash unit)
: Tot (accessor (gaccessor_fst_then g p2 u))
= accessor_compose (accessor_fst p1 u p2) a u
inline_for_extraction
let accessor_then_fst
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
: Tot (accessor (gaccessor_then_fst g))
= accessor_compose a (accessor_fst p1 () p2) ()
inline_for_extraction
let accessor_snd
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(j1: jumper p1)
(#k2: parser_kind)
(#t2: Type)
(p2: parser k2 t2)
: Tot (accessor (gaccessor_snd p1 p2))
= reveal_opaque (`%gaccessor_snd) (gaccessor_snd p1 p2);
fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_nondep_then h p1 p2 input pos in
let res = j1 input pos in
[@inline_let] let _ =
slice_access_eq h (gaccessor_snd p1 p2) input pos;
valid_facts p1 h input pos
in
res
inline_for_extraction
let accessor_then_snd
(#k0: parser_kind)
(#t0: Type)
(#p0: parser k0 t0)
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(#k2: parser_kind)
(#t2: Type)
(#p2: parser k2 t2)
(#cl: clens t0 (t1 & t2))
(#g: gaccessor p0 (p1 `nondep_then` p2) cl)
(a: accessor g)
(j1: jumper p1)
: Tot (accessor (gaccessor_then_snd g))
= accessor_compose a (accessor_snd j1 p2) ()
inline_for_extraction
let make_total_constant_size_reader
(sz: nat)
(sz' : U32.t { U32.v sz' == sz } )
(#t: Type)
(f: ((s: bytes {Seq.length s == sz}) -> GTot (t)))
(u: unit {
make_total_constant_size_parser_precond sz t f
})
(f' : ((#rrel: _) -> (#rel: _) -> (s: B.mbuffer byte rrel rel) -> (pos: U32.t) -> HST.Stack t
(requires (fun h -> B.live h s /\ U32.v pos + sz <= B.length s))
(ensures (fun h res h' ->
B.modifies B.loc_none h h' /\
res == f (Seq.slice (B.as_seq h s) (U32.v pos) (U32.v pos + sz))
))))
: Tot (leaf_reader (make_total_constant_size_parser sz t f))
= fun #rrel #rel sl pos ->
let h = HST.get () in
[@inline_let] let _ = valid_facts (make_total_constant_size_parser sz t f) h sl pos in
f' sl.base pos
let valid_filter
(#rrel #rel: _)
(h: HS.mem)
(#k: parser_kind)
(#t: Type)
(p: parser k t)
(f: (t -> GTot bool))
(input: slice rrel rel)
(pos: U32.t)
: Lemma
(
(valid (parse_filter p f) h input pos \/ (valid p h input pos /\ f (contents p h input pos))) ==> (
valid p h input pos /\
f (contents p h input pos) == true /\
valid_content_pos (parse_filter p f) h input pos (contents p h input pos) (get_valid_pos p h input pos)
))
= valid_facts (parse_filter p f) h input pos;
valid_facts p h input pos;
if U32.v pos <= U32.v input.len
then parse_filter_eq p f (bytes_of_slice_from h input pos)
inline_for_extraction
let validate_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then res
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then validator_error_generic
else res
inline_for_extraction
let validate_filter_with_error_code
(#k: parser_kind)
(#t: Type0)
(#p: parser k t)
(v32: validator p)
(p32: leaf_reader p)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input (uint64_to_uint32 pos) in
let res = v32 input pos in
if is_error res
then maybe_set_validator_error_pos_and_code res pos c
else
let va = p32 input (uint64_to_uint32 pos) in
if not (f' va)
then set_validator_error_pos_and_code validator_error_generic pos c
else res
inline_for_extraction
let validate_filter_ret
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then validator_error_generic
else pos
inline_for_extraction
let validate_filter_ret_with_error_code
(#t: Type0)
(r: t)
(f: (t -> GTot bool))
(f' : ((x: t) -> Tot (y: bool { y == f x } )))
(c: error_code)
: Tot (validator (parse_filter (parse_ret r) f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h (parse_ret r) f input (uint64_to_uint32 pos) in
[@inline_let] let _ = valid_facts (parse_ret r) h input (uint64_to_uint32 pos) in
if not (f' r)
then set_validator_error_pos_and_code validator_error_generic pos c
else pos
inline_for_extraction
let jump_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(j: jumper p)
(f: (t -> GTot bool))
: Tot (jumper (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
j input pos
inline_for_extraction
let read_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(p32: leaf_reader p)
(f: (t -> GTot bool))
: Tot (leaf_reader (parse_filter p f))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
(p32 input pos <: (res: t { f res == true } )) // FIXME: WHY WHY WHY do we need this coercion?
inline_for_extraction
let write_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_strong s)
(f: (t -> GTot bool))
: Tot (leaf_writer_strong (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let write_filter_weak
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: leaf_writer_weak s)
(f: (t -> GTot bool))
: Tot (leaf_writer_weak (serialize_filter s f))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialized_length_eq s x in
[@inline_let] let _ = serialized_length_eq (serialize_filter s f) x in
let res = s32 x input pos in
let h = HST.get () in
[@inline_let] let _ = valid_filter h p f input pos in
res
inline_for_extraction
let serialize32_filter
(#k: parser_kind)
(#t: Type)
(#p: parser k t)
(#s: serializer p)
(s32: serializer32 s)
(f: (t -> GTot bool))
: Tot (serializer32 (serialize_filter s f))
= fun x #rrel #rel input pos ->
s32 x input pos
inline_for_extraction
let read_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
let res = p1' input pos in
f2' res <: t2 // FIXME: WHY WHY WHY this coercion AND the separate let binding?
inline_for_extraction
let read_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_synth p1 f2 (fun x -> f2 x) p1' u
inline_for_extraction
let read_inline_synth
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> GTot t2)
(f2': (x: t1) -> Tot (y: t2 { y == f2 x } ))
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= fun #rrel #rel input pos ->
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
[@inline_let] let f2'' (x: t1) : HST.Stack t2 (requires (fun _ -> True)) (ensures (fun h y h' -> h == h' /\ y == f2 x)) = f2' x in // FIXME: WHY WHY WHY do I need this stateful function here? why can't I directly use f2' ?
f2'' (p1' input pos)
inline_for_extraction
let read_inline_synth'
(#k: parser_kind)
(#t1: Type)
(#t2: Type)
(p1: parser k t1)
(f2: t1 -> Tot t2)
(p1' : leaf_reader p1)
(u: unit {
synth_injective f2
})
: Tot (leaf_reader (parse_synth p1 f2))
= read_inline_synth p1 f2 (fun x -> f2 x) p1' ()
inline_for_extraction
let write_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_strong s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_strong (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let write_synth_weak
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : leaf_writer_weak s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (leaf_writer_weak (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ = serialize_synth_eq p1 f2 s1 g1 () x in
[@inline_let] let _ = serialized_length_eq (serialize_synth p1 f2 s1 g1 ()) x in
[@inline_let] let _ = serialized_length_eq s1 (g1 x) in
let pos' = s1' (g1' x) input pos in
let h = HST.get () in
[@inline_let] let _ = valid_synth h p1 f2 input pos in
pos'
inline_for_extraction
let serialize32_synth
(#k: parser_kind)
(#t1: Type)
(#p1: parser k t1)
(#s1: serializer p1)
(s1' : serializer32 s1)
(#t2: Type)
(f2: t1 -> GTot t2)
(g1: t2 -> GTot t1)
(g1' : (x2: t2) -> Tot (x1: t1 { x1 == g1 x2 } ))
(u: squash (synth_injective f2 /\ synth_inverse f2 g1))
: Tot (serializer32 (serialize_synth p1 f2 s1 g1 ()))
= fun x #rrel #rel input pos ->
[@inline_let] let _ =
serialize_synth_eq p1 f2 s1 g1 () x
in
s1' (g1' x) input pos
(* Special case for vldata and maybe also sum types *)
inline_for_extraction
let validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f' : ((x: t1) -> Tot (y: bool { y == f x } )))
(#k2: parser_kind)
(#t2: Type)
(#p2: ((x: t1 { f x == true} ) -> parser k2 t2))
(v2: ((x1: t1 { f x1 == true } ) -> validator (p2 x1)))
(u: unit {
and_then_cases_injective p2
}) | false | false | LowParse.Low.Combinators.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 16,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val validate_filter_and_then
(#k1: parser_kind)
(#t1: Type)
(#p1: parser k1 t1)
(v1: validator p1)
(p1': leaf_reader p1)
(f: (t1 -> GTot bool))
(f': (x: t1 -> Tot (y: bool{y == f x})))
(#k2: parser_kind)
(#t2: Type)
(#p2: (x: t1{f x == true} -> parser k2 t2))
(v2: (x1: t1{f x1 == true} -> validator (p2 x1)))
(u: unit{and_then_cases_injective p2})
: Tot (validator ((parse_filter p1 f) `and_then` p2)) | [] | LowParse.Low.Combinators.validate_filter_and_then | {
"file_name": "src/lowparse/LowParse.Low.Combinators.fsti",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} |
v1: LowParse.Low.Base.validator p1 ->
p1': LowParse.Low.Base.leaf_reader p1 ->
f: (_: t1 -> Prims.GTot Prims.bool) ->
f': (x: t1 -> y: Prims.bool{y == f x}) ->
v2: (x1: t1{f x1 == true} -> LowParse.Low.Base.validator (p2 x1)) ->
u525: u531: Prims.unit{LowParse.Spec.Combinators.and_then_cases_injective p2}
-> LowParse.Low.Base.validator (LowParse.Spec.Combinators.and_then (LowParse.Spec.Combinators.parse_filter
p1
f)
p2) | {
"end_col": 32,
"end_line": 1321,
"start_col": 2,
"start_line": 1301
} |
Prims.Tot | [
{
"abbrev": false,
"full_module": "FStar.Stubs.TypeChecker.Core",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics.Common",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Reflection.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Tactics",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let issues = list FStar.Issue.issue | let issues = | false | null | false | list FStar.Issue.issue | {
"checked_file": "FStar.Tactics.Types.fsti.checked",
"dependencies": [
"prims.fst.checked",
"FStar.Tactics.Common.fsti.checked",
"FStar.Stubs.TypeChecker.Core.fsti.checked",
"FStar.Reflection.Types.fsti.checked",
"FStar.Range.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Issue.fsti.checked"
],
"interface_file": false,
"source_file": "FStar.Tactics.Types.fsti"
} | [
"total"
] | [
"Prims.list",
"FStar.Issue.issue"
] | [] | (*
Copyright 2008-2018 Microsoft Research
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*)
module FStar.Tactics.Types
open FStar.Reflection.Types
include FStar.Tactics.Common
include FStar.Stubs.TypeChecker.Core
assume new type proofstate
assume new type goal
(* Returns the active goals *)
val goals_of : proofstate -> list goal
(* Returns the goals marked for SMT *)
val smt_goals_of : proofstate -> list goal
(* Inspecting a goal *)
val goal_env : goal -> env
val goal_type : goal -> typ
val goal_witness : goal -> term
val is_guard : goal -> bool (* A bit of helper info: did this goal come from a VC guard? *)
val get_label : goal -> string
val set_label : string -> goal -> goal
(* Tracing *)
val incr_depth : proofstate -> proofstate
val decr_depth : proofstate -> proofstate
(* [tracepoint] always returns true. We do not use unit to prevent
erasure. *)
val tracepoint : proofstate -> b:bool{b == true}
val set_proofstate_range : proofstate -> FStar.Range.range -> proofstate
type direction =
| TopDown
| BottomUp
type ctrl_flag =
| Continue
| Skip
| Abort
type guard_policy =
| Goal // Add guards as (normal) goals
| SMT // Add guards as SMT goals
| SMTSync // Send guards to SMT immediately, will *log* errors (not raise) if anything fails
| Force // Force guards without SMT
| Drop // Drop guards, clearly unsound! careful!
(* Typing reflection *)
val non_informative_token (g:env) (t:typ) : Type0
val subtyping_token (g:env) (t0 t1:typ) : Type0
val equiv_token (g:env) (t0 t1:typ) : Type0
val typing_token (g:env) (e:term) (c:tot_or_ghost & typ) : Type0
(* Must be inline, this definition is not there in src/FStar.Tactics.Types *) | false | false | FStar.Tactics.Types.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 1,
"max_fuel": 8,
"max_ifuel": 2,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": true,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val issues : Type0 | [] | FStar.Tactics.Types.issues | {
"file_name": "ulib/FStar.Tactics.Types.fsti",
"git_rev": "f4cbb7a38d67eeb13fbdb2f4fb8a44a65cbcdc1f",
"git_url": "https://github.com/FStarLang/FStar.git",
"project_name": "FStar"
} | Type0 | {
"end_col": 35,
"end_line": 71,
"start_col": 13,
"start_line": 71
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_check_mod_exp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t))) ->
Stack (limb t)
(requires fun h ->
live h n /\ live h a /\ live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) | let bn_check_mod_exp_st (t: limb_t) (len: BN.meta_len t) = | false | null | false |
n: lbignum t len ->
a: lbignum t len ->
bBits: size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} ->
b: lbignum t (blocks0 bBits (size (bits t)))
-> Stack (limb t)
(requires fun h -> live h n /\ live h a /\ live h b)
(ensures
fun h0 r h1 ->
modifies0 h0 h1 /\
r == S.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b)) | {
"checked_file": "Hacl.Bignum.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Exponentiation.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.limb",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.modifies0",
"Prims.eq2",
"Hacl.Spec.Bignum.Definitions.limb",
"Hacl.Spec.Bignum.Exponentiation.bn_check_mod_exp",
"Lib.Buffer.as_seq"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract | false | false | Hacl.Bignum.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_check_mod_exp_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.Exponentiation.bn_check_mod_exp_st | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 80,
"end_line": 29,
"start_col": 4,
"start_line": 21
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_st (t:limb_t) (len:BN.meta_len t) =
nBits:size_t
-> n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
v nBits / bits t < v len /\ pow2 (v nBits) < bn_v h n)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | let bn_mod_exp_st (t: limb_t) (len: BN.meta_len t) = | false | null | false |
nBits: size_t ->
n: lbignum t len ->
a: lbignum t len ->
bBits: size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t} ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
res: lbignum t len
-> Stack unit
(requires
fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ disjoint res a /\ disjoint res b /\
disjoint res n /\ disjoint n a /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
v nBits / bits t < v len /\ pow2 (v nBits) < bn_v h n)
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | {
"checked_file": "Hacl.Bignum.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Exponentiation.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.lbignum",
"Prims.b2t",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Lib.IntTypes.bits",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.max_size_t",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre",
"Lib.Buffer.as_seq",
"Prims.op_LessThan",
"Prims.op_Division",
"Prims.pow2",
"Hacl.Bignum.Definitions.bn_v",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_check_mod_exp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t))) ->
Stack (limb t)
(requires fun h ->
live h n /\ live h a /\ live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b))
inline_for_extraction noextract
val bn_check_mod_exp: #t:limb_t -> len:BN.meta_len t -> bn_check_mod_exp_st t len
inline_for_extraction noextract
let bn_mod_exp_precomp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> mu:limb t
-> r2:lbignum t len
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a /\
disjoint res r2 /\ disjoint a r2 /\ disjoint n r2 /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 (2 * bits t * v len) % bn_v h n /\
(1 + bn_v h n * v mu) % pow2 (bits t) == 0)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
inline_for_extraction noextract
val bn_mod_exp_bm_vartime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_bm_consttime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_fw_vartime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_fw_consttime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_bm_vartime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_bm_consttime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_fw_vartime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_fw_consttime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_consttime_precomp:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp_bm_consttime_precomp:bn_mod_exp_precomp_st t len
-> bn_mod_exp_fw_consttime_precomp:bn_mod_exp_precomp_st t len ->
bn_mod_exp_precomp_st t len
inline_for_extraction noextract
val bn_mod_exp_vartime_precomp:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp_bm_vartime_precomp:bn_mod_exp_precomp_st t len
-> bn_mod_exp_fw_vartime_precomp:bn_mod_exp_precomp_st t len ->
bn_mod_exp_precomp_st t len
inline_for_extraction noextract
let bn_mod_exp_precompr2_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> r2:lbignum t len
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a /\
disjoint res r2 /\ disjoint a r2 /\ disjoint n r2 /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 (2 * bits t * v len) % bn_v h n)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
inline_for_extraction noextract
val mk_bn_mod_exp_precompr2:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp_precomp:bn_mod_exp_precomp_st t len ->
bn_mod_exp_precompr2_st t len
inline_for_extraction noextract | false | false | Hacl.Bignum.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mod_exp_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_st | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 90,
"end_line": 161,
"start_col": 4,
"start_line": 147
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_precompr2_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> r2:lbignum t len
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a /\
disjoint res r2 /\ disjoint a r2 /\ disjoint n r2 /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 (2 * bits t * v len) % bn_v h n)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | let bn_mod_exp_precompr2_st (t: limb_t) (len: BN.meta_len t) = | false | null | false |
n: lbignum t len ->
r2: lbignum t len ->
a: lbignum t len ->
bBits: size_t ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
res: lbignum t len
-> Stack unit
(requires
fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\ disjoint res a /\
disjoint res b /\ disjoint res n /\ disjoint n a /\ disjoint res r2 /\ disjoint a r2 /\
disjoint n r2 /\ S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 ((2 * bits t) * v len) % bn_v h n)
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | {
"checked_file": "Hacl.Bignum.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Exponentiation.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Hacl.Bignum.Definitions.limb",
"Lib.Buffer.disjoint",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Prims.int",
"Hacl.Bignum.Definitions.bn_v",
"Prims.op_Modulus",
"Prims.pow2",
"FStar.Mul.op_Star",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_check_mod_exp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t))) ->
Stack (limb t)
(requires fun h ->
live h n /\ live h a /\ live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b))
inline_for_extraction noextract
val bn_check_mod_exp: #t:limb_t -> len:BN.meta_len t -> bn_check_mod_exp_st t len
inline_for_extraction noextract
let bn_mod_exp_precomp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> mu:limb t
-> r2:lbignum t len
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a /\
disjoint res r2 /\ disjoint a r2 /\ disjoint n r2 /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 (2 * bits t * v len) % bn_v h n /\
(1 + bn_v h n * v mu) % pow2 (bits t) == 0)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res))
inline_for_extraction noextract
val bn_mod_exp_bm_vartime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_bm_consttime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_fw_vartime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_fw_consttime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_bm_vartime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_bm_consttime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_fw_vartime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_amm_fw_consttime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
inline_for_extraction noextract
val bn_mod_exp_consttime_precomp:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp_bm_consttime_precomp:bn_mod_exp_precomp_st t len
-> bn_mod_exp_fw_consttime_precomp:bn_mod_exp_precomp_st t len ->
bn_mod_exp_precomp_st t len
inline_for_extraction noextract
val bn_mod_exp_vartime_precomp:
#t:limb_t
-> len:BN.meta_len t
-> bn_mod_exp_bm_vartime_precomp:bn_mod_exp_precomp_st t len
-> bn_mod_exp_fw_vartime_precomp:bn_mod_exp_precomp_st t len ->
bn_mod_exp_precomp_st t len
inline_for_extraction noextract | false | false | Hacl.Bignum.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mod_exp_precompr2_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_precompr2_st | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 90,
"end_line": 135,
"start_col": 4,
"start_line": 120
} |
|
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_precomp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> mu:limb t
-> r2:lbignum t len
-> a:lbignum t len
-> bBits:size_t
-> b:lbignum t (blocks0 bBits (size (bits t)))
-> res:lbignum t len ->
Stack unit
(requires fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\
disjoint res a /\ disjoint res b /\ disjoint res n /\ disjoint n a /\
disjoint res r2 /\ disjoint a r2 /\ disjoint n r2 /\
S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 (2 * bits t * v len) % bn_v h n /\
(1 + bn_v h n * v mu) % pow2 (bits t) == 0)
(ensures fun h0 _ h1 -> modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | let bn_mod_exp_precomp_st (t: limb_t) (len: BN.meta_len t) = | false | null | false |
n: lbignum t len ->
mu: limb t ->
r2: lbignum t len ->
a: lbignum t len ->
bBits: size_t ->
b: lbignum t (blocks0 bBits (size (bits t))) ->
res: lbignum t len
-> Stack unit
(requires
fun h ->
live h n /\ live h a /\ live h b /\ live h res /\ live h r2 /\ disjoint res a /\
disjoint res b /\ disjoint res n /\ disjoint n a /\ disjoint res r2 /\ disjoint a r2 /\
disjoint n r2 /\ S.bn_mod_exp_pre (as_seq h n) (as_seq h a) (v bBits) (as_seq h b) /\
bn_v h r2 == pow2 ((2 * bits t) * v len) % bn_v h n /\
(1 + bn_v h n * v mu) % pow2 (bits t) == 0)
(ensures
fun h0 _ h1 ->
modifies (loc res) h0 h1 /\
S.bn_mod_exp_post (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b) (as_seq h1 res)) | {
"checked_file": "Hacl.Bignum.Exponentiation.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fsti.checked",
"Hacl.Bignum.Montgomery.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Tactics.Typeclasses.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Hacl.Bignum.Exponentiation.fsti"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Prims.unit",
"FStar.Monotonic.HyperStack.mem",
"Prims.l_and",
"Lib.Buffer.live",
"Lib.Buffer.MUT",
"Lib.Buffer.disjoint",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_pre",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.Buffer.as_seq",
"Prims.eq2",
"Prims.int",
"Hacl.Bignum.Definitions.bn_v",
"Prims.op_Modulus",
"Prims.pow2",
"FStar.Mul.op_Star",
"Prims.op_Addition",
"Lib.IntTypes.SEC",
"Lib.Buffer.modifies",
"Lib.Buffer.loc",
"Hacl.Spec.Bignum.Exponentiation.bn_mod_exp_post"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module S = Hacl.Spec.Bignum.Exponentiation
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let bn_check_mod_exp_st (t:limb_t) (len:BN.meta_len t) =
n:lbignum t len
-> a:lbignum t len
-> bBits:size_t{bits t * v (blocks0 bBits (size (bits t))) <= max_size_t}
-> b:lbignum t (blocks0 bBits (size (bits t))) ->
Stack (limb t)
(requires fun h ->
live h n /\ live h a /\ live h b)
(ensures fun h0 r h1 -> modifies0 h0 h1 /\
r == S.bn_check_mod_exp (as_seq h0 n) (as_seq h0 a) (v bBits) (as_seq h0 b))
inline_for_extraction noextract
val bn_check_mod_exp: #t:limb_t -> len:BN.meta_len t -> bn_check_mod_exp_st t len
inline_for_extraction noextract | false | false | Hacl.Bignum.Exponentiation.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val bn_mod_exp_precomp_st : t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | t: Hacl.Bignum.Definitions.limb_t -> len: Hacl.Bignum.meta_len t -> Type0 | {
"end_col": 90,
"end_line": 55,
"start_col": 5,
"start_line": 38
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let uint8_p = B.buffer UInt8.t | let uint8_p = | false | null | false | B.buffer UInt8.t | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"total"
] | [
"LowStar.Buffer.buffer",
"FStar.UInt8.t"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic | false | true | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val uint8_p : Type0 | [] | Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 30,
"end_line": 24,
"start_col": 14,
"start_line": 24
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let uint64 = UInt64.t | let uint64 = | false | null | false | UInt64.t | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"total"
] | [
"FStar.UInt64.t"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic | false | true | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val uint64 : Prims.eqtype | [] | Vale.Wrapper.X64.GCMdecryptOpt256.uint64 | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Prims.eqtype | {
"end_col": 21,
"end_line": 25,
"start_col": 13,
"start_line": 25
} |
|
Prims.Tot | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2 | let disjoint_or_eq (b1 b2: uint8_p) = | false | null | false | B.disjoint b1 b2 \/ b1 == b2 | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"total"
] | [
"Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p",
"Prims.l_or",
"LowStar.Monotonic.Buffer.disjoint",
"FStar.UInt8.t",
"LowStar.Buffer.trivial_preorder",
"Prims.eq2",
"Prims.logical"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t | false | true | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val disjoint_or_eq : b1: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p -> b2: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p
-> Prims.logical | [] | Vale.Wrapper.X64.GCMdecryptOpt256.disjoint_or_eq | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b1: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p -> b2: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p
-> Prims.logical | {
"end_col": 65,
"end_line": 27,
"start_col": 37,
"start_line": 27
} |
|
FStar.Pervasives.Lemma | val length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0) | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_aux4 (b:uint8_p) : Lemma
(requires B.length b = 16)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | val length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0) = | false | null | true | let db = get_downview b in
DV.length_eq db | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"lemma"
] | [
"Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux3 (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 16 * n)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16
let length_aux4 (b:uint8_p) : Lemma | false | false | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_aux4 (b: uint8_p)
: Lemma (requires B.length b = 16) (ensures DV.length (get_downview b) % 16 = 0) | [] | Vale.Wrapper.X64.GCMdecryptOpt256.length_aux4 | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 16)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | {
"end_col": 19,
"end_line": 52,
"start_col": 49,
"start_line": 50
} |
FStar.Pervasives.Lemma | val length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0) | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_aux5 (b:uint8_p) : Lemma
(requires B.length b = 128)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | val length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0) = | false | null | true | let db = get_downview b in
DV.length_eq db | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"lemma"
] | [
"Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux3 (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 16 * n)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16
let length_aux4 (b:uint8_p) : Lemma
(requires B.length b = 16)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux5 (b:uint8_p) : Lemma | false | false | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_aux5 (b: uint8_p)
: Lemma (requires B.length b = 128) (ensures DV.length (get_downview b) % 16 = 0) | [] | Vale.Wrapper.X64.GCMdecryptOpt256.length_aux5 | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 128)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | {
"end_col": 19,
"end_line": 58,
"start_col": 49,
"start_line": 56
} |
FStar.Pervasives.Lemma | val length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | val length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) = | false | null | true | let db = get_downview b in
DV.length_eq db | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"lemma"
] | [
"Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma | false | false | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_aux (b: uint8_p)
: Lemma (requires B.length b = 176) (ensures DV.length (get_downview b) % 16 = 0) | [] | Vale.Wrapper.X64.GCMdecryptOpt256.length_aux | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 176)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | {
"end_col": 19,
"end_line": 33,
"start_col": 49,
"start_line": 31
} |
FStar.Pervasives.Lemma | val length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db | val length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) = | false | null | true | let db = get_downview b in
DV.length_eq db | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"lemma"
] | [
"Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.unit",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma | false | false | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_aux2 (b: uint8_p)
: Lemma (requires B.length b = 240) (ensures DV.length (get_downview b) % 16 = 0) | [] | Vale.Wrapper.X64.GCMdecryptOpt256.length_aux2 | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 240)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | {
"end_col": 19,
"end_line": 39,
"start_col": 49,
"start_line": 37
} |
FStar.Pervasives.Lemma | val length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0) | [
{
"abbrev": false,
"full_module": "Vale.AES.OptPublic",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Arch.Types",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Interop.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCTR_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GHash_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.AES_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AES.GCM_helpers",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Types_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words.Seq_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Def.Words_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.AsLowStar.MemoryHelpers",
"short_module": null
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Up",
"short_module": "UV"
},
{
"abbrev": true,
"full_module": "LowStar.BufferView.Down",
"short_module": "DV"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack",
"short_module": "HS"
},
{
"abbrev": true,
"full_module": "LowStar.Buffer",
"short_module": "B"
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.X64.CPU_Features_s",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "Vale.Wrapper.X64",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let length_aux3 (b:uint8_p) (n:nat) : Lemma
(requires B.length b = 16 * n)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16 | val length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0)
let length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0) = | false | null | true | let db = get_downview b in
DV.length_eq db;
FStar.Math.Lemmas.cancel_mul_mod n 16 | {
"checked_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti.checked",
"dependencies": [
"Vale.X64.CPU_Features_s.fst.checked",
"Vale.Wrapper.X64.GCMdecryptOpt.fsti.checked",
"Vale.Interop.Base.fst.checked",
"Vale.Def.Words_s.fsti.checked",
"Vale.Def.Words.Seq_s.fsti.checked",
"Vale.Def.Types_s.fst.checked",
"Vale.AsLowStar.MemoryHelpers.fsti.checked",
"Vale.Arch.Types.fsti.checked",
"Vale.AES.OptPublic.fsti.checked",
"Vale.AES.GHash_s.fst.checked",
"Vale.AES.GCTR_s.fst.checked",
"Vale.AES.GCTR.fsti.checked",
"Vale.AES.GCM_s.fst.checked",
"Vale.AES.GCM_helpers.fsti.checked",
"Vale.AES.AES_s.fst.checked",
"prims.fst.checked",
"LowStar.BufferView.Up.fsti.checked",
"LowStar.BufferView.Down.fsti.checked",
"LowStar.Buffer.fst.checked",
"FStar.UInt8.fsti.checked",
"FStar.UInt64.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Math.Lemmas.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": false,
"source_file": "Vale.Wrapper.X64.GCMdecryptOpt256.fsti"
} | [
"lemma"
] | [
"Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p",
"Prims.nat",
"FStar.Math.Lemmas.cancel_mul_mod",
"Prims.unit",
"LowStar.BufferView.Down.length_eq",
"FStar.UInt8.t",
"LowStar.BufferView.Down.buffer",
"Vale.Interop.Types.get_downview",
"Vale.Arch.HeapTypes_s.TUInt8",
"LowStar.Buffer.trivial_preorder",
"Prims.b2t",
"Prims.op_Equality",
"Prims.int",
"LowStar.Monotonic.Buffer.length",
"FStar.Mul.op_Star",
"Prims.squash",
"Prims.op_Modulus",
"LowStar.BufferView.Down.length",
"Prims.Nil",
"FStar.Pervasives.pattern"
] | [] | module Vale.Wrapper.X64.GCMdecryptOpt256
open Vale.X64.CPU_Features_s
open FStar.HyperStack.ST
module B = LowStar.Buffer
module HS = FStar.HyperStack
module DV = LowStar.BufferView.Down
module UV = LowStar.BufferView.Up
open Vale.AsLowStar.MemoryHelpers
open FStar.Mul
open Vale.Def.Words_s
open Vale.Def.Words.Seq_s
open Vale.Def.Types_s
open Vale.AES.GCM_helpers
open Vale.AES.AES_s
open Vale.AES.GCM_s
open Vale.AES.GHash_s
open Vale.AES.GCTR_s
open Vale.AES.GCTR
open Vale.Interop.Base
open Vale.Arch.Types
open Vale.AES.OptPublic
let uint8_p = B.buffer UInt8.t
let uint64 = UInt64.t
let disjoint_or_eq (b1 b2:uint8_p) = B.disjoint b1 b2 \/ b1 == b2
let length_aux (b:uint8_p) : Lemma
(requires B.length b = 176)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux2 (b:uint8_p) : Lemma
(requires B.length b = 240)
(ensures DV.length (get_downview b) % 16 = 0) =
let db = get_downview b in
DV.length_eq db
let length_aux3 (b:uint8_p) (n:nat) : Lemma | false | false | Vale.Wrapper.X64.GCMdecryptOpt256.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 2,
"initial_ifuel": 0,
"max_fuel": 1,
"max_ifuel": 1,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": true,
"smtencoding_l_arith_repr": "native",
"smtencoding_nl_arith_repr": "wrapped",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [
"smt.arith.nl=false",
"smt.QI.EAGER_THRESHOLD=100",
"smt.CASE_SPLIT=3"
],
"z3refresh": false,
"z3rlimit": 5,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val length_aux3 (b: uint8_p) (n: nat)
: Lemma (requires B.length b = 16 * n) (ensures DV.length (get_downview b) % 16 = 0) | [] | Vale.Wrapper.X64.GCMdecryptOpt256.length_aux3 | {
"file_name": "vale/code/arch/x64/interop/Vale.Wrapper.X64.GCMdecryptOpt256.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | b: Vale.Wrapper.X64.GCMdecryptOpt256.uint8_p -> n: Prims.nat
-> FStar.Pervasives.Lemma (requires LowStar.Monotonic.Buffer.length b = 16 * n)
(ensures LowStar.BufferView.Down.length (Vale.Interop.Types.get_downview b) % 16 = 0) | {
"end_col": 41,
"end_line": 46,
"start_col": 49,
"start_line": 43
} |
Prims.Tot | val t_limbs:Hacl.Bignum.Definitions.limb_t | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let t_limbs: Hacl.Bignum.Definitions.limb_t = Lib.IntTypes.U32 | val t_limbs:Hacl.Bignum.Definitions.limb_t
let t_limbs:Hacl.Bignum.Definitions.limb_t = | false | null | false | Lib.IntTypes.U32 | {
"checked_file": "Hacl.GenericField32.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.GenericField32.fsti"
} | [
"total"
] | [
"Lib.IntTypes.U32"
] | [] | module Hacl.GenericField32
open FStar.Mul
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0" | false | true | Hacl.GenericField32.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val t_limbs:Hacl.Bignum.Definitions.limb_t | [] | Hacl.GenericField32.t_limbs | {
"file_name": "code/bignum/Hacl.GenericField32.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Hacl.Bignum.Definitions.limb_t | {
"end_col": 62,
"end_line": 11,
"start_col": 46,
"start_line": 11
} |
Prims.Tot | [
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontArithmetic",
"short_module": "MA"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": false,
"full_module": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.Pervasives",
"short_module": null
},
{
"abbrev": false,
"full_module": "Prims",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar",
"short_module": null
}
] | false | let pbn_mont_ctx_u32 = MA.pbn_mont_ctx_u32 | let pbn_mont_ctx_u32 = | false | null | false | MA.pbn_mont_ctx_u32 | {
"checked_file": "Hacl.GenericField32.fsti.checked",
"dependencies": [
"prims.fst.checked",
"Lib.IntTypes.fsti.checked",
"Hacl.Bignum.MontArithmetic.fsti.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.Ghost.fsti.checked"
],
"interface_file": false,
"source_file": "Hacl.GenericField32.fsti"
} | [
"total"
] | [
"Hacl.Bignum.MontArithmetic.pbn_mont_ctx_u32"
] | [] | module Hacl.GenericField32
open FStar.Mul
module BN = Hacl.Bignum
module MA = Hacl.Bignum.MontArithmetic
#set-options "--z3rlimit 50 --fuel 0 --ifuel 0"
inline_for_extraction noextract
let t_limbs: Hacl.Bignum.Definitions.limb_t = Lib.IntTypes.U32 | false | true | Hacl.GenericField32.fsti | {
"detail_errors": false,
"detail_hint_replay": false,
"initial_fuel": 0,
"initial_ifuel": 0,
"max_fuel": 0,
"max_ifuel": 0,
"no_plugins": false,
"no_smt": false,
"no_tactics": false,
"quake_hi": 1,
"quake_keep": false,
"quake_lo": 1,
"retry": false,
"reuse_hint_for": null,
"smtencoding_elim_box": false,
"smtencoding_l_arith_repr": "boxwrap",
"smtencoding_nl_arith_repr": "boxwrap",
"smtencoding_valid_elim": false,
"smtencoding_valid_intro": true,
"tcnorm": true,
"trivial_pre_for_unannotated_effectful_fns": false,
"z3cliopt": [],
"z3refresh": false,
"z3rlimit": 50,
"z3rlimit_factor": 1,
"z3seed": 0,
"z3smtopt": [],
"z3version": "4.8.5"
} | null | val pbn_mont_ctx_u32 : Type0 | [] | Hacl.GenericField32.pbn_mont_ctx_u32 | {
"file_name": "code/bignum/Hacl.GenericField32.fsti",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | Type0 | {
"end_col": 42,
"end_line": 13,
"start_col": 23,
"start_line": 13
} |
|
FStar.Pervasives.Lemma | val inversion_tuple2 (a b: Type) : Lemma (inversion (tuple2 a b)) [SMTPat (tuple2 a b)] | [
{
"abbrev": false,
"full_module": "LowParse.Low.VLGen",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.DER",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.BCVLI",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.VCList",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.IfThenElse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Tac.Sum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Sum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Option",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Enum",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.VLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Bytes",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Array",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.FLData",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.List",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Int",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Combinators",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse.Low.Base",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": false,
"full_module": "LowParse",
"short_module": null
},
{
"abbrev": 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 inversion_tuple2 (a b: Type) : Lemma (inversion (tuple2 a b)) [SMTPat (tuple2 a b)] = allow_inversion (tuple2 a b) | val inversion_tuple2 (a b: Type) : Lemma (inversion (tuple2 a b)) [SMTPat (tuple2 a b)]
let inversion_tuple2 (a b: Type) : Lemma (inversion (tuple2 a b)) [SMTPat (tuple2 a b)] = | false | null | true | allow_inversion (tuple2 a b) | {
"checked_file": "LowParse.Low.fst.checked",
"dependencies": [
"prims.fst.checked",
"LowParse.Low.VLGen.fst.checked",
"LowParse.Low.VLData.fst.checked",
"LowParse.Low.VCList.fst.checked",
"LowParse.Low.Tac.Sum.fst.checked",
"LowParse.Low.Sum.fst.checked",
"LowParse.Low.Option.fst.checked",
"LowParse.Low.List.fst.checked",
"LowParse.Low.Int.fsti.checked",
"LowParse.Low.IfThenElse.fst.checked",
"LowParse.Low.FLData.fst.checked",
"LowParse.Low.Enum.fst.checked",
"LowParse.Low.DER.fst.checked",
"LowParse.Low.Combinators.fsti.checked",
"LowParse.Low.Bytes.fst.checked",
"LowParse.Low.BCVLI.fst.checked",
"LowParse.Low.Base.fst.checked",
"LowParse.Low.Array.fst.checked",
"FStar.Pervasives.fsti.checked"
],
"interface_file": false,
"source_file": "LowParse.Low.fst"
} | [
"lemma"
] | [
"FStar.Pervasives.allow_inversion",
"FStar.Pervasives.Native.tuple2",
"Prims.unit",
"Prims.l_True",
"Prims.squash",
"FStar.Pervasives.inversion",
"Prims.Cons",
"FStar.Pervasives.pattern",
"FStar.Pervasives.smt_pat",
"Prims.Nil"
] | [] | module LowParse.Low
include LowParse.Low.Base
include LowParse.Low.Combinators
include LowParse.Low.Int
include LowParse.Low.List
include LowParse.Low.FLData
include LowParse.Low.Array
include LowParse.Low.Bytes
include LowParse.Low.VLData
include LowParse.Low.Enum
include LowParse.Low.Option
include LowParse.Low.Sum
include LowParse.Low.Tac.Sum
include LowParse.Low.IfThenElse
include LowParse.Low.VCList
include LowParse.Low.BCVLI
include LowParse.Low.DER
include LowParse.Low.VLGen | false | false | LowParse.Low.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 inversion_tuple2 (a b: Type) : Lemma (inversion (tuple2 a b)) [SMTPat (tuple2 a b)] | [] | LowParse.Low.inversion_tuple2 | {
"file_name": "src/lowparse/LowParse.Low.fst",
"git_rev": "446a08ce38df905547cf20f28c43776b22b8087a",
"git_url": "https://github.com/project-everest/everparse.git",
"project_name": "everparse"
} | a: Type -> b: Type
-> FStar.Pervasives.Lemma (ensures FStar.Pervasives.inversion (a * b)) [SMTPat (a * b)] | {
"end_col": 118,
"end_line": 20,
"start_col": 90,
"start_line": 20
} |
Prims.Tot | val bn_mod_exp_consttime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len) | val bn_mod_exp_consttime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len
let bn_mod_exp_consttime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len = | false | null | false | mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp",
"Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len) | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_consttime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U32
-> Hacl.Bignum.Exponentiation.bn_mod_exp_st Lib.IntTypes.U32 len | {
"end_col": 91,
"end_line": 175,
"start_col": 2,
"start_line": 175
} |
Prims.Tot | val bn_mod_exp_consttime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_consttime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_consttime_precomp_u64 len) | val bn_mod_exp_consttime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len
let bn_mod_exp_consttime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len = | false | null | false | mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_consttime_precomp_u64 len) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp",
"Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_vartime_precomp_u64 len) | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_consttime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U64
-> Hacl.Bignum.Exponentiation.bn_mod_exp_st Lib.IntTypes.U64 len | {
"end_col": 91,
"end_line": 208,
"start_col": 2,
"start_line": 208
} |
Prims.Tot | val bn_check_mod_exp_u32 (len: BN.meta_len U32) : bn_check_mod_exp_st U32 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len | val bn_check_mod_exp_u32 (len: BN.meta_len U32) : bn_check_mod_exp_st U32 len
let bn_check_mod_exp_u32 (len: BN.meta_len U32) : bn_check_mod_exp_st U32 len = | false | null | false | bn_check_mod_exp len | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation. | false | false | Hacl.Bignum.Exponentiation.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 bn_check_mod_exp_u32 (len: BN.meta_len U32) : bn_check_mod_exp_st U32 len | [] | Hacl.Bignum.Exponentiation.bn_check_mod_exp_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U32
-> Hacl.Bignum.Exponentiation.bn_check_mod_exp_st Lib.IntTypes.U32 len | {
"end_col": 22,
"end_line": 159,
"start_col": 2,
"start_line": 159
} |
Prims.Tot | val bn_check_mod_exp_u64 (len: BN.meta_len U64) : bn_check_mod_exp_st U64 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len | val bn_check_mod_exp_u64 (len: BN.meta_len U64) : bn_check_mod_exp_st U64 len
let bn_check_mod_exp_u64 (len: BN.meta_len U64) : bn_check_mod_exp_st U64 len = | false | null | false | bn_check_mod_exp len | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
} | false | false | Hacl.Bignum.Exponentiation.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 bn_check_mod_exp_u64 (len: BN.meta_len U64) : bn_check_mod_exp_st U64 len | [] | Hacl.Bignum.Exponentiation.bn_check_mod_exp_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U64
-> Hacl.Bignum.Exponentiation.bn_check_mod_exp_st Lib.IntTypes.U64 len | {
"end_col": 22,
"end_line": 192,
"start_col": 2,
"start_line": 192
} |
Prims.Tot | val bn_mod_exp_vartime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len) | val bn_mod_exp_vartime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len
let bn_mod_exp_vartime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len = | false | null | false | mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp",
"Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul) | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_vartime_u32 (len: BN.meta_len U32) : bn_mod_exp_st U32 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U32
-> Hacl.Bignum.Exponentiation.bn_mod_exp_st Lib.IntTypes.U32 len | {
"end_col": 89,
"end_line": 173,
"start_col": 2,
"start_line": 173
} |
Prims.Tot | val bn_mod_exp_vartime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_vartime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_vartime_precomp_u64 len) | val bn_mod_exp_vartime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len
let bn_mod_exp_vartime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len = | false | null | false | mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_vartime_precomp_u64 len) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp",
"Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul) | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_vartime_u64 (len: BN.meta_len U64) : bn_mod_exp_st U64 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U64
-> Hacl.Bignum.Exponentiation.bn_mod_exp_st Lib.IntTypes.U64 len | {
"end_col": 89,
"end_line": 206,
"start_col": 2,
"start_line": 206
} |
FStar.Pervasives.Lemma | val mk_runtime_exp_len_lemma: #t:limb_t -> len:BN.meta_len t ->
Lemma ((mk_runtime_exp #t len).bn.BN.len == len) [SMTPat (mk_runtime_exp #t len)] | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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_runtime_exp_len_lemma #t len =
BM.mk_runtime_mont_len_lemma #t len | val mk_runtime_exp_len_lemma: #t:limb_t -> len:BN.meta_len t ->
Lemma ((mk_runtime_exp #t len).bn.BN.len == len) [SMTPat (mk_runtime_exp #t len)]
let mk_runtime_exp_len_lemma #t len = | false | null | true | BM.mk_runtime_mont_len_lemma #t len | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"lemma"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Montgomery.mk_runtime_mont_len_lemma",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_vartime_precomp_u64 len)
let bn_mod_exp_consttime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_consttime_precomp_u64 len)
inline_for_extraction noextract
let mk_runtime_exp_u64 (len:BN.meta_len U64) : exp U64 = {
bn = BN.mk_runtime_bn U64 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u64 len;
precompr2 = BM.bn_precomp_r2_mod_n_u64 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u64 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u64 len;
exp_vt = bn_mod_exp_vartime_u64 len;
exp_ct = bn_mod_exp_consttime_u64 len;
}
let mk_runtime_exp (#t:limb_t) (len:BN.meta_len t) : exp t =
match t with
| U32 -> mk_runtime_exp_u32 len
| U64 -> mk_runtime_exp_u64 len | false | false | Hacl.Bignum.Exponentiation.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 mk_runtime_exp_len_lemma: #t:limb_t -> len:BN.meta_len t ->
Lemma ((mk_runtime_exp #t len).bn.BN.len == len) [SMTPat (mk_runtime_exp #t len)] | [] | Hacl.Bignum.Exponentiation.mk_runtime_exp_len_lemma | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len t
-> FStar.Pervasives.Lemma
(ensures Mkbn?.len (Mkexp?.bn (Hacl.Bignum.Exponentiation.mk_runtime_exp len)) == len)
[SMTPat (Hacl.Bignum.Exponentiation.mk_runtime_exp len)] | {
"end_col": 37,
"end_line": 230,
"start_col": 2,
"start_line": 230
} |
Prims.Tot | val bn_mod_exp_fw_vartime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res | val bn_mod_exp_fw_vartime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Montgomery.mont",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.Montgomery.__proj__Mkmont__item__bn",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_mont",
"Hacl.Bignum.MontExponentiation.bn_exp_mont_fw_vartime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_fw_vartime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_fw_vartime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Bignum.Montgomery.mont t ->
l:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits Lib.IntTypes.U32 /\
Prims.pow2 (Lib.IntTypes.v l) * Lib.IntTypes.v (Mkbn?.len (Mkmont?.bn k)) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkmont?.bn k)) | {
"end_col": 90,
"end_line": 108,
"start_col": 2,
"start_line": 108
} |
Prims.Tot | val bn_mod_exp_amm_bm_vartime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res | val bn_mod_exp_amm_bm_vartime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.AlmostMontgomery.__proj__Mkalmost_mont__item__bn",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont",
"Hacl.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_bm_vartime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_amm_bm_vartime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_vartime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Hacl.Bignum.AlmostMontgomery.almost_mont t
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkalmost_mont?.bn k)) | {
"end_col": 96,
"end_line": 114,
"start_col": 2,
"start_line": 114
} |
Prims.Tot | val bn_mod_exp_amm_fw_vartime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res | val bn_mod_exp_amm_fw_vartime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.AlmostMontgomery.__proj__Mkalmost_mont__item__bn",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont",
"Hacl.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_fw_vartime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_amm_fw_vartime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_vartime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Bignum.AlmostMontgomery.almost_mont t ->
l:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits Lib.IntTypes.U32 /\
Prims.pow2 (Lib.IntTypes.v l) * Lib.IntTypes.v (Mkbn?.len (Mkalmost_mont?.bn k)) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkalmost_mont?.bn k)) | {
"end_col": 98,
"end_line": 120,
"start_col": 2,
"start_line": 120
} |
Prims.Tot | val bn_mod_exp_fw_consttime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res | val bn_mod_exp_fw_consttime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Montgomery.mont",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.Montgomery.__proj__Mkmont__item__bn",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_mont",
"Hacl.Bignum.MontExponentiation.bn_exp_mont_fw_consttime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_fw_consttime_precomp:
#t:limb_t
-> k:BM.mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.BM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_fw_consttime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Bignum.Montgomery.mont t ->
l:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits Lib.IntTypes.U32 /\
Prims.pow2 (Lib.IntTypes.v l) * Lib.IntTypes.v (Mkbn?.len (Mkmont?.bn k)) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkmont?.bn k)) | {
"end_col": 92,
"end_line": 111,
"start_col": 2,
"start_line": 111
} |
Prims.Tot | val bn_mod_exp_bm_vartime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res | val bn_mod_exp_bm_vartime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Montgomery.mont",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.Montgomery.__proj__Mkmont__item__bn",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_mont",
"Hacl.Bignum.MontExponentiation.bn_exp_mont_bm_vartime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame () | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_bm_vartime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_bm_vartime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Hacl.Bignum.Montgomery.mont t
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkmont?.bn k)) | {
"end_col": 88,
"end_line": 102,
"start_col": 2,
"start_line": 102
} |
Prims.Tot | val bn_mod_exp_bm_consttime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res | val bn_mod_exp_bm_consttime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.Montgomery.mont",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.Montgomery.__proj__Mkmont__item__bn",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_mont",
"Hacl.Bignum.MontExponentiation.bn_exp_mont_bm_consttime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_bm_consttime_precomp: #t:limb_t -> k:BM.mont t -> bn_mod_exp_precomp_st t k.BM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_bm_consttime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Hacl.Bignum.Montgomery.mont t
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkmont?.bn k)) | {
"end_col": 90,
"end_line": 105,
"start_col": 2,
"start_line": 105
} |
Prims.Tot | val mk_runtime_exp: #t:limb_t -> len:BN.meta_len t -> exp t | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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_runtime_exp (#t:limb_t) (len:BN.meta_len t) : exp t =
match t with
| U32 -> mk_runtime_exp_u32 len
| U64 -> mk_runtime_exp_u64 len | val mk_runtime_exp: #t:limb_t -> len:BN.meta_len t -> exp t
let mk_runtime_exp (#t: limb_t) (len: BN.meta_len t) : exp t = | false | null | false | match t with
| U32 -> mk_runtime_exp_u32 len
| U64 -> mk_runtime_exp_u64 len | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.meta_len",
"Hacl.Bignum.Exponentiation.mk_runtime_exp_u32",
"Hacl.Bignum.Exponentiation.mk_runtime_exp_u64",
"Hacl.Bignum.Exponentiation.exp"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_vartime_precomp_u64 len)
let bn_mod_exp_consttime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_consttime_precomp_u64 len)
inline_for_extraction noextract
let mk_runtime_exp_u64 (len:BN.meta_len U64) : exp U64 = {
bn = BN.mk_runtime_bn U64 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u64 len;
precompr2 = BM.bn_precomp_r2_mod_n_u64 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u64 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u64 len;
exp_vt = bn_mod_exp_vartime_u64 len;
exp_ct = bn_mod_exp_consttime_u64 len;
} | false | false | Hacl.Bignum.Exponentiation.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 mk_runtime_exp: #t:limb_t -> len:BN.meta_len t -> exp t | [] | Hacl.Bignum.Exponentiation.mk_runtime_exp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len t -> Hacl.Bignum.Exponentiation.exp t | {
"end_col": 33,
"end_line": 227,
"start_col": 2,
"start_line": 225
} |
Prims.Tot | val bn_mod_exp_amm_fw_consttime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res | val bn_mod_exp_amm_fw_consttime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Lib.IntTypes.size_t",
"Prims.l_and",
"Prims.b2t",
"Prims.op_LessThan",
"Lib.IntTypes.v",
"Lib.IntTypes.U32",
"Lib.IntTypes.PUB",
"Lib.IntTypes.bits",
"Prims.op_LessThanOrEqual",
"FStar.Mul.op_Star",
"Prims.pow2",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.AlmostMontgomery.__proj__Mkalmost_mont__item__bn",
"Lib.IntTypes.max_size_t",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.Definitions.limb",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont",
"Hacl.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_fw_consttime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_amm_fw_consttime_precomp:
#t:limb_t
-> k:AM.almost_mont t
-> l:size_t{0 < v l /\ v l < bits U32 /\ pow2 (v l) * v k.AM.bn.BN.len <= max_size_t} ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_consttime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} |
k: Hacl.Bignum.AlmostMontgomery.almost_mont t ->
l:
Lib.IntTypes.size_t
{ 0 < Lib.IntTypes.v l /\ Lib.IntTypes.v l < Lib.IntTypes.bits Lib.IntTypes.U32 /\
Prims.pow2 (Lib.IntTypes.v l) * Lib.IntTypes.v (Mkbn?.len (Mkalmost_mont?.bn k)) <=
Lib.IntTypes.max_size_t }
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkalmost_mont?.bn k)) | {
"end_col": 100,
"end_line": 123,
"start_col": 2,
"start_line": 123
} |
Prims.Tot | val bn_mod_exp_amm_bm_consttime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res | val bn_mod_exp_amm_bm_consttime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res = | false | null | false | mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.Definitions.limb_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Hacl.Bignum.Definitions.lbignum",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.AlmostMontgomery.__proj__Mkalmost_mont__item__bn",
"Hacl.Bignum.Definitions.limb",
"Lib.IntTypes.size_t",
"Hacl.Bignum.Definitions.blocks0",
"Lib.IntTypes.size",
"Lib.IntTypes.bits",
"Hacl.Bignum.Exponentiation.mk_bn_mod_exp_precomp_amont",
"Hacl.Bignum.AlmostMontExponentiation.bn_exp_almost_mont_bm_consttime",
"Prims.unit"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_amm_bm_consttime_precomp: #t:limb_t -> k:AM.almost_mont t -> bn_mod_exp_precomp_st t k.AM.bn.BN.len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_consttime_precomp | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | k: Hacl.Bignum.AlmostMontgomery.almost_mont t
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st t (Mkbn?.len (Mkalmost_mont?.bn k)) | {
"end_col": 98,
"end_line": 117,
"start_col": 2,
"start_line": 117
} |
Prims.Tot | val bn_mod_exp_consttime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul) | val bn_mod_exp_consttime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len
let bn_mod_exp_consttime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len = | false | null | false | [@@ inline_let ]let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_consttime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_consttime_precomp",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Hacl.Bignum.AlmostMontgomery.mk_runtime_almost_mont",
"Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul) | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_consttime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U32
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st Lib.IntTypes.U32 len | {
"end_col": 48,
"end_line": 171,
"start_col": 2,
"start_line": 167
} |
Prims.Tot | val mk_runtime_exp_u64 (len: BN.meta_len U64) : exp U64 | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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_runtime_exp_u64 (len:BN.meta_len U64) : exp U64 = {
bn = BN.mk_runtime_bn U64 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u64 len;
precompr2 = BM.bn_precomp_r2_mod_n_u64 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u64 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u64 len;
exp_vt = bn_mod_exp_vartime_u64 len;
exp_ct = bn_mod_exp_consttime_u64 len;
} | val mk_runtime_exp_u64 (len: BN.meta_len U64) : exp U64
let mk_runtime_exp_u64 (len: BN.meta_len U64) : exp U64 = | false | null | false | {
bn = BN.mk_runtime_bn U64 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u64 len;
precompr2 = BM.bn_precomp_r2_mod_n_u64 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u64 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u64 len;
exp_vt = bn_mod_exp_vartime_u64 len;
exp_ct = bn_mod_exp_consttime_u64 len
} | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Exponentiation.Mkexp",
"Hacl.Bignum.mk_runtime_bn",
"Hacl.Bignum.Montgomery.bn_check_modulus",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp_u64",
"Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_u64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_u64",
"Hacl.Bignum.Exponentiation.exp"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_vartime_precomp_u64 len)
let bn_mod_exp_consttime_u64 (len:BN.meta_len U64) : bn_mod_exp_st U64 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u64 len) (bn_mod_exp_consttime_precomp_u64 len)
inline_for_extraction noextract | false | true | Hacl.Bignum.Exponentiation.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 mk_runtime_exp_u64 (len: BN.meta_len U64) : exp U64 | [] | Hacl.Bignum.Exponentiation.mk_runtime_exp_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U64 -> Hacl.Bignum.Exponentiation.exp Lib.IntTypes.U64 | {
"end_col": 40,
"end_line": 220,
"start_col": 2,
"start_line": 213
} |
Prims.Tot | val bn_mod_exp_consttime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_consttime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul) | val bn_mod_exp_consttime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len
let bn_mod_exp_consttime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len = | false | null | false | [@@ inline_let ]let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_consttime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_consttime_precomp",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Hacl.Bignum.AlmostMontgomery.mk_runtime_almost_mont",
"Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul) | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_consttime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U64
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st Lib.IntTypes.U64 len | {
"end_col": 48,
"end_line": 204,
"start_col": 2,
"start_line": 200
} |
Prims.Tot | val mk_runtime_exp_u32 (len: BN.meta_len U32) : exp U32 | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
} | val mk_runtime_exp_u32 (len: BN.meta_len U32) : exp U32
let mk_runtime_exp_u32 (len: BN.meta_len U32) : exp U32 = | false | null | false | {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len
} | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Exponentiation.Mkexp",
"Hacl.Bignum.mk_runtime_bn",
"Hacl.Bignum.Montgomery.bn_check_modulus",
"Hacl.Bignum.__proj__Mkbn__item__len",
"Hacl.Bignum.Exponentiation.bn_check_mod_exp_u32",
"Hacl.Bignum.Montgomery.bn_precomp_r2_mod_n_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_precomp_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_u32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_consttime_u32",
"Hacl.Bignum.Exponentiation.exp"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract | false | true | Hacl.Bignum.Exponentiation.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 mk_runtime_exp_u32 (len: BN.meta_len U32) : exp U32 | [] | Hacl.Bignum.Exponentiation.mk_runtime_exp_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U32 -> Hacl.Bignum.Exponentiation.exp Lib.IntTypes.U32 | {
"end_col": 40,
"end_line": 187,
"start_col": 2,
"start_line": 180
} |
Prims.Tot | val bn_mod_exp_vartime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_vartime_precomp_u64 (len:BN.meta_len U64) : bn_mod_exp_precomp_st U64 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul) | val bn_mod_exp_vartime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len
let bn_mod_exp_vartime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len = | false | null | false | [@@ inline_let ]let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U64",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_vartime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_vartime_precomp",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Hacl.Bignum.AlmostMontgomery.mk_runtime_almost_mont",
"Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len
let bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul)
let bn_mod_exp_consttime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_consttime_precomp len
(bn_mod_exp_amm_bm_consttime_precomp km)
(bn_mod_exp_amm_fw_consttime_precomp km 4ul)
let bn_mod_exp_vartime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_vartime_precomp_u32 len)
let bn_mod_exp_consttime_u32 (len:BN.meta_len U32) : bn_mod_exp_st U32 len =
mk_bn_mod_exp len (BM.bn_precomp_r2_mod_n_u32 len) (bn_mod_exp_consttime_precomp_u32 len)
inline_for_extraction noextract
let mk_runtime_exp_u32 (len:BN.meta_len U32) : exp U32 = {
bn = BN.mk_runtime_bn U32 len;
mod_check = BM.bn_check_modulus;
exp_check = bn_check_mod_exp_u32 len;
precompr2 = BM.bn_precomp_r2_mod_n_u32 len;
exp_vt_precomp = bn_mod_exp_vartime_precomp_u32 len;
exp_ct_precomp = bn_mod_exp_consttime_precomp_u32 len;
exp_vt = bn_mod_exp_vartime_u32 len;
exp_ct = bn_mod_exp_consttime_u32 len;
}
let bn_check_mod_exp_u64 (len:BN.meta_len U64) : bn_check_mod_exp_st U64 len =
bn_check_mod_exp len | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_vartime_precomp_u64 (len: BN.meta_len U64) : bn_mod_exp_precomp_st U64 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp_u64 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U64
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st Lib.IntTypes.U64 len | {
"end_col": 46,
"end_line": 198,
"start_col": 2,
"start_line": 194
} |
Prims.Tot | val bn_mod_exp_vartime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len | [
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.MontExponentiation",
"short_module": "SE"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Montgomery.Lemmas",
"short_module": "M"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Exponentiation.Lemmas",
"short_module": "E"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontExponentiation",
"short_module": "AE"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.MontExponentiation",
"short_module": "ME"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Montgomery",
"short_module": "SM"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Definitions",
"short_module": "BD"
},
{
"abbrev": true,
"full_module": "FStar.HyperStack.ST",
"short_module": "ST"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.AlmostMontgomery",
"short_module": "AM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum.Montgomery",
"short_module": "BM"
},
{
"abbrev": true,
"full_module": "Hacl.Bignum",
"short_module": "BN"
},
{
"abbrev": true,
"full_module": "Hacl.Spec.Bignum.Exponentiation",
"short_module": "S"
},
{
"abbrev": false,
"full_module": "Hacl.Bignum.Definitions",
"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": "FStar.Mul",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack.ST",
"short_module": null
},
{
"abbrev": false,
"full_module": "FStar.HyperStack",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": false,
"full_module": "Hacl.Bignum",
"short_module": null
},
{
"abbrev": 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 bn_mod_exp_vartime_precomp_u32 (len:BN.meta_len U32) : bn_mod_exp_precomp_st U32 len =
[@inline_let]
let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul) | val bn_mod_exp_vartime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len
let bn_mod_exp_vartime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len = | false | null | false | [@@ inline_let ]let km = AM.mk_runtime_almost_mont len in
bn_mod_exp_vartime_precomp len
(bn_mod_exp_amm_bm_vartime_precomp km)
(bn_mod_exp_amm_fw_vartime_precomp km 4ul) | {
"checked_file": "Hacl.Bignum.Exponentiation.fst.checked",
"dependencies": [
"prims.fst.checked",
"Lib.NatMod.fsti.checked",
"Lib.IntTypes.fsti.checked",
"Lib.Buffer.fsti.checked",
"Hacl.Spec.Montgomery.Lemmas.fst.checked",
"Hacl.Spec.Exponentiation.Lemmas.fst.checked",
"Hacl.Spec.Bignum.Montgomery.fsti.checked",
"Hacl.Spec.Bignum.MontExponentiation.fst.checked",
"Hacl.Spec.Bignum.ModInvLimb.fsti.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Exponentiation.fst.checked",
"Hacl.Spec.Bignum.Definitions.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.Montgomery.fst.checked",
"Hacl.Bignum.MontExponentiation.fst.checked",
"Hacl.Bignum.Definitions.fst.checked",
"Hacl.Bignum.AlmostMontgomery.fsti.checked",
"Hacl.Bignum.AlmostMontExponentiation.fst.checked",
"Hacl.Bignum.fsti.checked",
"FStar.UInt32.fsti.checked",
"FStar.Pervasives.fsti.checked",
"FStar.Mul.fst.checked",
"FStar.HyperStack.ST.fsti.checked",
"FStar.HyperStack.fst.checked"
],
"interface_file": true,
"source_file": "Hacl.Bignum.Exponentiation.fst"
} | [
"total"
] | [
"Hacl.Bignum.meta_len",
"Lib.IntTypes.U32",
"Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_bm_vartime_precomp",
"Hacl.Bignum.Exponentiation.bn_mod_exp_amm_fw_vartime_precomp",
"FStar.UInt32.__uint_to_t",
"Hacl.Bignum.AlmostMontgomery.almost_mont",
"Hacl.Bignum.AlmostMontgomery.mk_runtime_almost_mont",
"Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st"
] | [] | module Hacl.Bignum.Exponentiation
open FStar.HyperStack
open FStar.HyperStack.ST
open FStar.Mul
open Lib.IntTypes
open Lib.Buffer
open Hacl.Bignum.Definitions
module ST = FStar.HyperStack.ST
module BD = Hacl.Spec.Bignum.Definitions
module SM = Hacl.Spec.Bignum.Montgomery
module BN = Hacl.Bignum
module BM = Hacl.Bignum.Montgomery
module AM = Hacl.Bignum.AlmostMontgomery
module ME = Hacl.Bignum.MontExponentiation
module AE = Hacl.Bignum.AlmostMontExponentiation
module E = Hacl.Spec.Exponentiation.Lemmas
module M = Hacl.Spec.Montgomery.Lemmas
module SE = Hacl.Spec.Bignum.MontExponentiation
module S = Hacl.Spec.Bignum.Exponentiation
friend Hacl.Spec.Bignum.Exponentiation
friend Hacl.Bignum.Montgomery
#reset-options "--z3rlimit 50 --fuel 0 --ifuel 0"
let bn_check_mod_exp #t len n a bBits b =
let m0 = BM.bn_check_modulus n in
let bLen = blocks0 bBits (size (bits t)) in
let m1 =
if bBits <. size (bits t) *! bLen
then BN.bn_lt_pow2_mask bLen b bBits
else ones t SEC in
let m2 = BN.bn_lt_mask len a n in
let m = m1 &. m2 in
m0 &. m
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_mont:
#t:limb_t
-> k:BM.mont t
-> bn_exp_mont: ME.bn_exp_mont_st t k.BM.bn.BN.len ->
bn_mod_exp_precomp_st t k.BM.bn.BN.len
let mk_bn_mod_exp_precomp_mont #t k bn_exp_mont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.BM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
BM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_mont n mu r2 aM bBits b resM;
BM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
E.mod_exp_mont_ll_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
inline_for_extraction noextract
val mk_bn_mod_exp_precomp_amont:
#t:limb_t
-> k:AM.almost_mont t
-> bn_exp_amont: AE.bn_exp_almost_mont_st t k.AM.bn.BN.len ->
bn_mod_exp_precomp_st t k.AM.bn.BN.len
let mk_bn_mod_exp_precomp_amont #t k bn_exp_amont n mu r2 a bBits b res =
let h0 = ST.get () in
[@inline_let] let len = k.AM.bn.BN.len in
push_frame ();
BD.bn_eval_bound (as_seq h0 n) (v len);
let aM = create len (uint #t #SEC 0) in
AM.to n mu r2 a aM;
SM.bn_to_mont_lemma (as_seq h0 n) mu (as_seq h0 r2) (as_seq h0 a);
M.to_mont_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a);
let resM = create len (uint #t #SEC 0) in
bn_exp_amont n mu r2 aM bBits b resM;
AM.from n mu resM res;
let h1 = ST.get () in
SM.bn_from_mont_lemma (as_seq h0 n) mu (as_seq h1 resM);
BD.bn_eval_bound (as_seq h1 resM) (v len);
E.mod_exp_mont_ll_mod_lemma (bits t) (v len) (bn_v h0 n) (v mu) (bn_v h0 a) (bn_v h0 b) (bn_v h1 resM);
assert (bn_v h1 res == Lib.NatMod.pow_mod #(bn_v h0 n) (bn_v h0 a) (bn_v h0 b));
pop_frame ()
let bn_mod_exp_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_mont #t k (ME.bn_exp_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_vartime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_vartime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_bm_consttime_precomp #t k n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_bm_consttime #t k) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_vartime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_vartime #t k l) n mu r2 a bBits b res
let bn_mod_exp_amm_fw_consttime_precomp #t k l n mu r2 a bBits b res =
mk_bn_mod_exp_precomp_amont #t k (AE.bn_exp_almost_mont_fw_consttime #t k l) n mu r2 a bBits b res
let bn_mod_exp_consttime_precomp #t len bn_mod_exp_bm_consttime_precomp bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_consttime_threshold then
bn_mod_exp_bm_consttime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_consttime_precomp n mu r2 a bBits b res
let bn_mod_exp_vartime_precomp #t len bn_mod_exp_bm_vartime_precomp bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res =
if bBits <. size SE.bn_exp_mont_vartime_threshold then
bn_mod_exp_bm_vartime_precomp n mu r2 a bBits b res
else
bn_mod_exp_fw_vartime_precomp n mu r2 a bBits b res
let mk_bn_mod_exp_precompr2 #t len bn_mod_exp_precomp n r2 a bBits b res =
let h0 = ST.get () in
let mu = BM.mod_inv_limb n.(0ul) in // n * mu = 1 (mod (pow2 64))
Hacl.Spec.Bignum.ModInvLimb.bn_mod_inv_limb_lemma (as_seq h0 n);
bn_mod_exp_precomp n mu r2 a bBits b res
let mk_bn_mod_exp #t len precomp_r2 bn_mod_exp_precomp nBits n a bBits b res =
push_frame ();
let r2 = create len (uint #t #SEC 0) in
let mu = BM.bn_mont_precomp len precomp_r2 nBits n r2 in
bn_mod_exp_precomp n mu r2 a bBits b res;
pop_frame ()
///////////////////////////////////////////////
/// A fully runtime implementation of modular exponentiation.
let bn_check_mod_exp_u32 (len:BN.meta_len U32) : bn_check_mod_exp_st U32 len =
bn_check_mod_exp len | false | false | Hacl.Bignum.Exponentiation.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 bn_mod_exp_vartime_precomp_u32 (len: BN.meta_len U32) : bn_mod_exp_precomp_st U32 len | [] | Hacl.Bignum.Exponentiation.bn_mod_exp_vartime_precomp_u32 | {
"file_name": "code/bignum/Hacl.Bignum.Exponentiation.fst",
"git_rev": "12c5e9539c7e3c366c26409d3b86493548c4483e",
"git_url": "https://github.com/hacl-star/hacl-star.git",
"project_name": "hacl-star"
} | len: Hacl.Bignum.meta_len Lib.IntTypes.U32
-> Hacl.Bignum.Exponentiation.bn_mod_exp_precomp_st Lib.IntTypes.U32 len | {
"end_col": 46,
"end_line": 165,
"start_col": 2,
"start_line": 161
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.