effect
stringclasses
48 values
original_source_type
stringlengths
0
23k
opens_and_abbrevs
listlengths
2
92
isa_cross_project_example
bool
1 class
source_definition
stringlengths
9
57.9k
partial_definition
stringlengths
7
23.3k
is_div
bool
2 classes
is_type
null
is_proof
bool
2 classes
completed_definiton
stringlengths
1
250k
dependencies
dict
effect_flags
sequencelengths
0
2
ideal_premises
sequencelengths
0
236
mutual_with
sequencelengths
0
11
file_context
stringlengths
0
407k
interleaved
bool
1 class
is_simply_typed
bool
2 classes
file_name
stringlengths
5
48
vconfig
dict
is_simple_lemma
null
source_type
stringlengths
10
23k
proof_features
sequencelengths
0
1
name
stringlengths
8
95
source
dict
verbose_type
stringlengths
1
7.42k
source_range
dict
FStar.Pervasives.Lemma
val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j)
[ { "abbrev": false, "full_module": "MerkleTree.New.High", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs)
val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs =
false
null
true
if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs)
{ "checked_file": "MerkleTree.New.High.Correct.Base.fst.checked", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ "lemma", "" ]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_AmpAmp", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.pow2", "Prims.op_Subtraction", "MerkleTree.New.High.hashess", "Prims.l_and", "Prims.op_Equality", "Prims.int", "FStar.Seq.Base.length", "MerkleTree.New.High.hashes", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv", "Prims.bool", "MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted_", "Prims.op_Addition", "Prims.op_Division", "Prims.unit", "MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_", "MerkleTree.New.High.Correct.Base.log2c_bound" ]
[]
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2"
false
false
MerkleTree.New.High.Correct.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 0, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j)
[ "recursion" ]
MerkleTree.New.High.Correct.Base.mt_hashes_inv_log_converted_
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
lv: Prims.nat{lv <= 32} -> j: Prims.nat{j > 0 && j < Prims.pow2 (32 - lv)} -> fhs: MerkleTree.New.High.hashess { FStar.Seq.Base.length fhs = 32 /\ MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv lv j fhs } -> FStar.Pervasives.Lemma (requires MerkleTree.New.High.Correct.Base.mt_hashes_inv lv j fhs) (ensures ([@@ FStar.Pervasives.inline_let ]let _ = MerkleTree.New.High.Correct.Base.log2c_bound j (32 - lv) in [@@ FStar.Pervasives.inline_let ]let _ = MerkleTree.New.High.Correct.Base.mt_hashes_lth_inv_log_converted_ lv j fhs in MerkleTree.New.High.Correct.Base.mt_hashes_inv_log j (FStar.Seq.Base.slice fhs lv (lv + MerkleTree.New.High.Correct.Base.log2c j)))) (decreases j)
{ "end_col": 64, "end_line": 390, "start_col": 2, "start_line": 387 }
FStar.Pervasives.Lemma
val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd)))
[ { "abbrev": false, "full_module": "MerkleTree.New.High", "short_module": null }, { "abbrev": true, "full_module": "MerkleTree.Spec", "short_module": "MTS" }, { "abbrev": true, "full_module": "FStar.Seq", "short_module": "S" }, { "abbrev": false, "full_module": "FStar.Seq", "short_module": null }, { "abbrev": false, "full_module": "FStar.Ghost", "short_module": null }, { "abbrev": false, "full_module": "FStar.Classical", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "MerkleTree.New.High.Correct", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then begin MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in // assume (MTS.mt_next_rel #_ #f n mt nmt); MTS.mt_next_rel_next_lv #_ #f n mt nmt end else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd)
val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) let hash_seq_spec_full_even_next #hsz #f j hs nhs acc actd =
false
null
true
log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; if actd then (MTS.mt_next_rel_upd_even_pad #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) (S.length hs / 2) (MTS.HRaw acc); let n = log2c j in let mt = S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc) in let nmt = S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw acc) in MTS.mt_next_rel_next_lv #_ #f n mt nmt) else MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec_full #_ #f hs acc actd) (hash_seq_spec_full #_ #f nhs acc actd)
{ "checked_file": "MerkleTree.New.High.Correct.Base.fst.checked", "dependencies": [ "prims.fst.checked", "MerkleTree.Spec.fst.checked", "MerkleTree.New.High.fst.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked" ], "interface_file": false, "source_file": "MerkleTree.New.High.Correct.Base.fst" }
[ "lemma" ]
[ "Prims.pos", "MerkleTree.Spec.hash_fun_t", "Prims.nat", "Prims.b2t", "Prims.op_GreaterThan", "MerkleTree.New.High.hashes", "Prims.op_Equality", "FStar.Seq.Base.length", "MerkleTree.New.High.hash", "Prims.int", "Prims.op_Division", "Prims.bool", "MerkleTree.Spec.mt_next_rel_next_lv", "FStar.Seq.Base.seq", "MerkleTree.Spec.padded_hash", "FStar.Seq.Base.upd", "MerkleTree.New.High.Correct.Base.hash_seq_spec", "MerkleTree.Spec.HRaw", "Prims.op_BarBar", "Prims.op_AmpAmp", "Prims.op_LessThanOrEqual", "Prims.pow2", "Prims.op_Subtraction", "Prims.op_LessThan", "MerkleTree.New.High.Correct.Base.log2c", "Prims.unit", "MerkleTree.Spec.mt_next_rel_upd_even_pad", "MerkleTree.New.High.Correct.Base.hash_seq_spec_full", "MerkleTree.New.High.Correct.Base.mt_hashes_next_rel_lift_even", "MerkleTree.New.High.Correct.Base.log2c_div" ]
[]
module MerkleTree.New.High.Correct.Base open FStar.Classical open FStar.Ghost open FStar.Seq module S = FStar.Seq module MTS = MerkleTree.Spec open MerkleTree.New.High #set-options "--z3rlimit 40 --max_fuel 0 --max_ifuel 0" /// Sequence helpers val seq_prefix: #a:Type -> s1:S.seq a -> s2:S.seq a{S.length s1 <= S.length s2} -> GTot Type0 let seq_prefix #a s1 s2 = S.equal s1 (S.slice s2 0 (S.length s1)) val seq_head_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.head (S.cons x s) == x) [SMTPat (S.cons x s)] let seq_head_cons #a x s = () val seq_tail_cons: #a:Type -> x:a -> s:S.seq a -> Lemma (S.equal (S.tail (S.cons x s)) s) [SMTPat (S.cons x s)] let seq_tail_cons #a x s = () /// Invariants and simulation relation of high-level Merkle tree design // Invariants of internal hashes val empty_hashes: (#hsz:pos) -> (len:nat) -> GTot (hs:hashess #hsz {S.length hs = len}) let empty_hashes #hsz len = S.create len S.empty val empty_hashes_head: #hsz:pos -> len:nat{len > 0} -> Lemma (S.head (empty_hashes #hsz len) == S.empty) let empty_hashes_head #_ _ = () val empty_hashes_tail: #hsz:pos -> len:nat{len > 0} -> Lemma (S.equal (S.tail (empty_hashes len)) (empty_hashes #hsz (len - 1))) let empty_hashes_tail #_ _ = () #push-options "--max_fuel 1" val mt_hashes_lth_inv: #hsz:pos -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_lth_inv #hsz lv j fhs = if lv = 32 then true else (S.length (S.index fhs lv) == j /\ mt_hashes_lth_inv (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_empty: #hsz:pos -> lv:nat{lv <= 32} -> Lemma (requires True) (ensures mt_hashes_lth_inv lv 0 (empty_hashes #hsz 32)) (decreases (32 - lv)) let rec mt_hashes_lth_inv_empty #hsz lv = if lv = 32 then () else mt_hashes_lth_inv_empty #hsz (lv + 1) val mt_hashes_next_rel: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> GTot Type0 let mt_hashes_next_rel #hsz #f j hs nhs = forall (i:nat{i < j / 2}). S.index nhs i == f (S.index hs (op_Multiply 2 i)) (S.index hs (op_Multiply 2 i + 1)) #pop-options #push-options "--max_fuel 2" val mt_hashes_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv lv j fhs} -> GTot Type0 (decreases (32 - lv)) let rec mt_hashes_inv #hsz #f lv j fhs = if lv = 31 then true else (mt_hashes_next_rel #_ #f j (S.index fhs lv) (S.index fhs (lv + 1)) /\ mt_hashes_inv #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_inv_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> Lemma (requires True) (ensures (mt_hashes_lth_inv_empty #hsz lv; mt_hashes_inv #hsz #f lv 0 (empty_hashes #hsz 32))) (decreases (32 - lv)) let rec mt_hashes_inv_empty #hsz #f lv = if lv = 31 then () else (mt_hashes_lth_inv_empty #hsz (lv + 1); mt_hashes_inv_empty #_ #f (lv + 1)) val mt_hashes_lth_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess{S.length fhs1 = 32} -> fhs2:hashess{S.length fhs2 = 32} -> Lemma (requires mt_hashes_lth_inv lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_lth_inv #hsz lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_lth_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); mt_hashes_lth_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) #pop-options #push-options "--max_fuel 1" val mt_hashes_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> j:nat{j < pow2 (32 - lv)} -> fhs1:hashess #hsz {S.length fhs1 = 32 /\ mt_hashes_lth_inv lv j fhs1} -> fhs2:hashess #hsz {S.length fhs2 = 32 /\ mt_hashes_lth_inv lv j fhs2} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs1 /\ S.equal (S.slice fhs1 lv 32) (S.slice fhs2 lv 32)) (ensures mt_hashes_inv #_ #f lv j fhs2) (decreases (32 - lv)) let rec mt_hashes_inv_equiv #hsz #f lv j fhs1 fhs2 = if lv = 31 then () else (assert (S.index fhs1 lv == S.index fhs2 lv); assert (S.index fhs1 (lv + 1) == S.index fhs2 (lv + 1)); mt_hashes_inv_equiv #_ #f (lv + 1) (j / 2) fhs1 fhs2) val merge_hs: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> GTot (mhs:hashess #hsz {S.length mhs = S.length hs1}) (decreases (S.length hs1)) let rec merge_hs #hsz #f hs1 hs2 = if S.length hs1 = 0 then S.empty else (S.cons (S.append (S.head hs1) (S.head hs2)) (merge_hs #_ #f (S.tail hs1) (S.tail hs2))) val merge_hs_empty: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> len:nat -> Lemma (S.equal (merge_hs #_ #f (empty_hashes #hsz len) (empty_hashes #hsz len)) (empty_hashes #hsz len)) let rec merge_hs_empty #hsz #f len = if len = 0 then () else (empty_hashes_head #hsz len; empty_hashes_tail #hsz len; assert (S.equal (S.append #(hash #hsz) S.empty S.empty) (S.empty #(hash #hsz))); assert (S.equal (merge_hs #_ #f (empty_hashes len) (empty_hashes len)) (S.cons S.empty (merge_hs #_ #f (empty_hashes (len - 1)) (empty_hashes (len - 1))))); merge_hs_empty #_ #f (len - 1)) val merge_hs_index: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess -> hs2:hashess{S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> Lemma (requires True) (ensures S.equal (S.index (merge_hs #_ #f hs1 hs2) i) (S.append (S.index hs1 i) (S.index hs2 i))) (decreases (S.length hs1)) [SMTPat (S.index (merge_hs #_ #f hs1 hs2) i)] let rec merge_hs_index #hsz #f hs1 hs2 i = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_index #_ #f (S.tail hs1) (S.tail hs2) (i - 1) val merge_hs_slice_equal: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> ahs1:hashess #hsz -> ahs2:hashess #hsz {S.length ahs1 = S.length ahs2} -> bhs1:hashess #hsz -> bhs2:hashess #hsz {S.length bhs1 = S.length bhs2} -> i:nat -> j:nat{i <= j && j <= S.length ahs1 && j <= S.length bhs1} -> Lemma (requires S.equal (S.slice ahs1 i j) (S.slice bhs1 i j) /\ S.equal (S.slice ahs2 i j) (S.slice bhs2 i j)) (ensures S.equal (S.slice (merge_hs #_ #f ahs1 ahs2) i j) (S.slice (merge_hs #_ #f bhs1 bhs2) i j)) (decreases (j - i)) let rec merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 i j = if i = j then () else (assert (S.index ahs1 i == S.index bhs1 i); assert (S.index ahs2 i == S.index bhs2 i); merge_hs_slice_equal #_ #f ahs1 ahs2 bhs1 bhs2 (i + 1) j) val merge_hs_upd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs1:hashess #hsz -> hs2:hashess #hsz {S.length hs1 = S.length hs2} -> i:nat{i < S.length hs1} -> v1:hashes #hsz -> v2:hashes #hsz -> Lemma (requires S.equal (S.append (S.index hs1 i) (S.index hs2 i)) (S.append v1 v2)) (ensures S.equal (merge_hs #_ #f hs1 hs2) (merge_hs #_ #f (S.upd hs1 i v1) (S.upd hs2 i v2))) (decreases i) let rec merge_hs_upd #_ #f hs1 hs2 i v1 v2 = if S.length hs1 = 0 then () else if i = 0 then () else merge_hs_upd #_ #f (S.tail hs1) (S.tail hs2) (i - 1) v1 v2 val mt_olds_inv: #hsz:pos -> lv:nat{lv <= 32} -> i:nat -> olds:hashess #hsz {S.length olds = 32} -> GTot Type0 (decreases (32 - lv)) let rec mt_olds_inv #hsz lv i olds = if lv = 32 then true else (let ofs = offset_of i in S.length (S.index olds lv) == ofs /\ mt_olds_inv #hsz (lv + 1) (i / 2) olds) val mt_olds_inv_equiv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> olds1:hashess #hsz {S.length olds1 = 32} -> olds2:hashess #hsz {S.length olds2 = 32} -> Lemma (requires mt_olds_inv #hsz lv i olds1 /\ S.equal (S.slice olds1 lv 32) (S.slice olds2 lv 32)) (ensures mt_olds_inv #hsz lv i olds2) (decreases (32 - lv)) let rec mt_olds_inv_equiv #hsz #f lv i olds1 olds2 = if lv = 32 then () else (assert (S.index olds1 lv == S.index olds2 lv); mt_olds_inv_equiv #_ #f (lv + 1) (i / 2) olds1 olds2) val mt_olds_hs_lth_inv_ok: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts #hsz lv hs i j} -> Lemma (requires True) (ensures mt_hashes_lth_inv #hsz lv j (merge_hs #_ #f olds hs)) (decreases (32 - lv)) let rec mt_olds_hs_lth_inv_ok #hsz #f lv i j olds hs = if lv = 32 then () else (mt_olds_hs_lth_inv_ok #_ #f (lv + 1) (i / 2) (j / 2) olds hs) val mt_olds_hs_inv: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv < 32} -> i:nat -> j:nat{i <= j /\ j < pow2 (32 - lv)} -> olds:hashess #hsz {S.length olds = 32 /\ mt_olds_inv #hsz lv i olds} -> hs:hashess #hsz {S.length hs = 32 /\ hs_wf_elts #hsz lv hs i j} -> GTot Type0 let mt_olds_hs_inv #hsz #f lv i j olds hs = mt_olds_hs_lth_inv_ok #_ #f lv i j olds hs; mt_hashes_inv #_ #f lv j (merge_hs #_ #f olds hs) // Relation between valid internal hashes (satisfying `mt_olds_hs_inv`) and // the spec. While giving such relation, all rightmost hashes are recovered. // Note that `MT?.rhs` after `construct_rhs` does NOT contain all rightmost // hashes; it has partial rightmost hashes that are enough to calculate // Merkle paths. val log2: n:nat{n > 0} -> GTot (c:nat{pow2 c <= n && n < pow2 (c+1)}) let rec log2 n = if n = 1 then 0 else 1 + log2 (n / 2) val log2_bound: n:nat{n > 0} -> c:nat{n < pow2 c} -> Lemma (log2 n <= c-1) let rec log2_bound n c = if n = 1 then () else log2_bound (n / 2) (c - 1) val log2_div: n:nat{n > 1} -> Lemma (log2 (n / 2) = log2 n - 1) let log2_div n = () val log2c: n:nat -> GTot (c:nat{c = 0 || (pow2 (c-1) <= n && n < pow2 c)}) let log2c n = if n = 0 then 0 else (log2 n + 1) val log2c_div: n:nat{n > 0} -> Lemma (log2c (n / 2) = log2c n - 1) let log2c_div n = () val log2c_bound: n:nat -> c:nat{n < pow2 c} -> Lemma (log2c n <= c) let rec log2c_bound n c = if n = 0 then () else log2c_bound (n / 2) (c - 1) val mt_hashes_lth_inv_log: #hsz:pos -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j} -> GTot Type0 (decreases j) let rec mt_hashes_lth_inv_log #hsz j fhs = if j = 0 then true else (S.length (S.head fhs) == j /\ mt_hashes_lth_inv_log #hsz (j / 2) (S.tail fhs)) #pop-options #push-options "--max_fuel 2" val mt_hashes_lth_inv_log_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> fhs:hashess #hsz {S.length fhs = log2c j} -> Lemma (requires mt_hashes_lth_inv_log #hsz j fhs) (ensures S.length (S.head fhs) == j /\ S.length (S.head (S.tail fhs)) == j / 2) let mt_hashes_lth_inv_log_next #_ #_ _ _ = () val mt_hashes_inv_log: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat -> fhs:hashess #hsz {S.length fhs = log2c j /\ mt_hashes_lth_inv_log #hsz j fhs} -> GTot Type0 (decreases j) let rec mt_hashes_inv_log #hsz #f j fhs = if j <= 1 then true else (mt_hashes_next_rel #_ #f j (S.index fhs 0) (S.index fhs 1) /\ mt_hashes_inv_log #_ #f (j / 2) (S.tail fhs)) val mt_hashes_lth_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log #hsz j (S.slice fhs lv (lv + log2c j)))) (decreases j) let rec mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs = if j = 0 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) val mt_hashes_lth_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32} -> Lemma (requires mt_hashes_lth_inv #hsz 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log #hsz j (S.slice fhs 0 (log2c j)))) let mt_hashes_lth_inv_log_converted #_ #f j fhs = mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs val mt_hashes_inv_log_converted_: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> lv:nat{lv <= 32} -> j:nat{j > 0 && j < pow2 (32 - lv)} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz lv j fhs} -> Lemma (requires mt_hashes_inv #_ #f lv j fhs) (ensures (log2c_bound j (32 - lv); mt_hashes_lth_inv_log_converted_ #_ #f lv j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs lv (lv + log2c j)))) (decreases j) #pop-options #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" let rec mt_hashes_inv_log_converted_ #_ #f lv j fhs = if j = 1 then () else (log2c_bound (j / 2) (32 - (lv + 1)); mt_hashes_lth_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs; mt_hashes_inv_log_converted_ #_ #f (lv + 1) (j / 2) fhs) #pop-options val mt_hashes_inv_log_converted: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0 && j < pow2 32} -> fhs:hashess #hsz {S.length fhs = 32 /\ mt_hashes_lth_inv #hsz 0 j fhs} -> Lemma (requires mt_hashes_inv #_ #f 0 j fhs) (ensures (log2c_bound j 32; mt_hashes_lth_inv_log_converted_ #_ #f 0 j fhs; mt_hashes_inv_log #_ #f j (S.slice fhs 0 (log2c j)))) let mt_hashes_inv_log_converted #_ #f j fhs = mt_hashes_inv_log_converted_ #_ #f 0 j fhs val hash_seq_lift: #hsz:pos -> hs:hashes #hsz -> GTot (shs:MTS.hashes #hsz {S.length shs = S.length hs}) (decreases (S.length hs)) let rec hash_seq_lift #hsz hs = if S.length hs = 0 then S.empty else S.cons (MTS.HRaw (S.head hs)) (hash_seq_lift #hsz (S.tail hs)) #push-options "--z3rlimit 50 --initial_fuel 2 --max_fuel 2" val hash_seq_lift_index: #hsz:pos -> hs:hashes #hsz -> Lemma (requires True) (ensures forall (i:nat{i < S.length hs}). S.index (hash_seq_lift #hsz hs) i == MTS.HRaw (S.index hs i)) (decreases (S.length hs)) let rec hash_seq_lift_index #hsz hs = if S.length hs = 0 then () else hash_seq_lift_index #hsz (S.tail hs) #pop-options val create_pads: #hsz:pos -> len:nat -> GTot (pads:MTS.hashes #hsz {S.length pads = len}) let create_pads #hsz len = S.create len (MTS.HPad #hsz) val hash_seq_spec: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec #hsz hs = S.append (hash_seq_lift #hsz hs) (create_pads (pow2 (log2c (S.length hs)) - S.length hs)) val hash_seq_spec_index_raw: #hsz:pos -> hs:hashes #hsz {S.length hs > 0} -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec #hsz hs) i == MTS.HRaw #hsz (S.index hs i)) let hash_seq_spec_index_raw #hsz hs i = hash_seq_lift_index #hsz hs // Now about recovering rightmost hashes #push-options "--z3rlimit 50 --initial_fuel 1 --max_fuel 1" val mt_hashes_next_rel_lift_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs)) let mt_hashes_next_rel_lift_even #hsz #_ j hs nhs = hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_lift_odd: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 1 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures MTS.mt_next_rel #_ #f (log2c j) (hash_seq_spec #hsz hs) (S.upd (hash_seq_spec #hsz nhs) (S.length nhs) (MTS.HRaw (S.last hs)))) let mt_hashes_next_rel_lift_odd #hsz #_ j hs nhs = log2c_div j; hash_seq_lift_index #hsz hs; hash_seq_lift_index #hsz nhs val mt_hashes_next_rel_next_even: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 1} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec #hsz nhs) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec #hsz hs))) let mt_hashes_next_rel_next_even #hsz #f j hs nhs = log2c_div j; mt_hashes_next_rel_lift_even #_ #f j hs nhs; MTS.mt_next_rel_next_lv #_ #f (log2c j) (hash_seq_spec #hsz hs) (hash_seq_spec #hsz nhs) val hash_seq_spec_full: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> GTot (MTS.merkle_tree #hsz (log2c (S.length hs))) let hash_seq_spec_full #hsz #f hs acc actd = if actd then (S.upd (hash_seq_spec #hsz hs) (S.length hs) (MTS.HRaw acc)) else hash_seq_spec #hsz hs val hash_seq_spec_full_index_raw: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> actd:bool -> i:nat{i < S.length hs} -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc actd) i == MTS.HRaw (S.index hs i)) let hash_seq_spec_full_index_raw #hsz #_ hs acc actd i = hash_seq_spec_index_raw #hsz hs i val hash_seq_spec_full_case_true: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> hs:hashes #hsz {S.length hs > 0} -> acc:hash #hsz -> Lemma (S.index (hash_seq_spec_full #_ #f hs acc true) (S.length hs) == MTS.HRaw acc) let hash_seq_spec_full_case_true #_ #_ _ _ = () val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd))) #restart-solver #push-options "--quake 1/3 --z3rlimit 100 --fuel 2 --ifuel 1"
false
false
MerkleTree.New.High.Correct.Base.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 2, "max_ifuel": 1, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 3, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "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": 100, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val hash_seq_spec_full_even_next: #hsz:pos -> #f:MTS.hash_fun_t #hsz -> j:nat{j > 0} -> hs:hashes #hsz {S.length hs = j} -> nhs:hashes #hsz {S.length nhs = j / 2} -> acc:hash #hsz -> actd:bool -> Lemma (requires j % 2 = 0 /\ mt_hashes_next_rel #_ #f j hs nhs) (ensures S.equal (hash_seq_spec_full #_ #f nhs acc actd) (MTS.mt_next_lv #_ #f #(log2c j) (hash_seq_spec_full #_ #f hs acc actd)))
[]
MerkleTree.New.High.Correct.Base.hash_seq_spec_full_even_next
{ "file_name": "src/MerkleTree.New.High.Correct.Base.fst", "git_rev": "3b0f086655c145aa23f58a97259ebf4cf112a4a3", "git_url": "https://github.com/hacl-star/merkle-tree.git", "project_name": "merkle-tree" }
j: Prims.nat{j > 0} -> hs: MerkleTree.New.High.hashes{FStar.Seq.Base.length hs = j} -> nhs: MerkleTree.New.High.hashes{FStar.Seq.Base.length nhs = j / 2} -> acc: MerkleTree.New.High.hash -> actd: Prims.bool -> FStar.Pervasives.Lemma (requires j % 2 = 0 /\ MerkleTree.New.High.Correct.Base.mt_hashes_next_rel j hs nhs) (ensures FStar.Seq.Base.equal (MerkleTree.New.High.Correct.Base.hash_seq_spec_full nhs acc actd) (MerkleTree.Spec.mt_next_lv (MerkleTree.New.High.Correct.Base.hash_seq_spec_full hs acc actd)))
{ "end_col": 48, "end_line": 542, "start_col": 2, "start_line": 528 }
Prims.Tot
val clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); }
val clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) let clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) =
false
null
false
{ clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))) }
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "FStar.Bytes.lbytes", "LowParse.Low.Bytes.clens_vlbytes_cond", "Prims.l_True", "LowParse.Low.Base.Spec.clens" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length))
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clens_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length))
[]
LowParse.Low.Bytes.clens_vlbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: Prims.nat -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max) (FStar.Bytes.lbytes length)
{ "end_col": 167, "end_line": 607, "start_col": 2, "start_line": 606 }
Prims.Tot
val validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max)
val validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max)) let validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max)) =
false
null
false
validate_bounded_vlbytes' min max (log256' max)
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Bytes.validate_bounded_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.validator", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (validator (parse_bounded_vlbytes min max))
[]
LowParse.Low.Bytes.validate_bounded_vlbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_bounded_vlbytes min max)
{ "end_col": 49, "end_line": 369, "start_col": 2, "start_line": 369 }
Prims.Tot
val jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 ()
val jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz)) let jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz)) =
false
null
false
jump_constant_size (parse_flbytes sz) sz32 ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "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.Low.Base.jump_constant_size", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.jumper" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val jump_flbytes (sz: nat) (sz32: U32.t{U32.v sz32 == sz}) : Tot (jumper (parse_flbytes sz))
[]
LowParse.Low.Bytes.jump_flbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat -> sz32: FStar.UInt32.t{FStar.UInt32.v sz32 == sz} -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_flbytes sz)
{ "end_col": 47, "end_line": 30, "start_col": 2, "start_line": 30 }
Prims.Tot
val clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); }
val clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) =
false
null
false
{ clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))) }
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "FStar.UInt32.t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Base.Spec.Mkclens", "FStar.Bytes.lbytes", "Prims.op_Subtraction", "Prims.l_True", "FStar.Bytes.slice", "LowParse.Low.Base.Spec.clens" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from)))
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from)))
[]
LowParse.Low.Bytes.clens_flbytes_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.Spec.clens (FStar.Bytes.lbytes sz) (FStar.Bytes.lbytes (FStar.UInt32.v to - FStar.UInt32.v from))
{ "end_col": 99, "end_line": 77, "start_col": 2, "start_line": 76 }
Prims.Tot
val clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte)
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); }
val clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) let clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) =
false
null
false
{ clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)) }
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Bytes.byte", "FStar.UInt32.v", "FStar.Bytes.length", "FStar.Bytes.get", "LowParse.Low.Base.Spec.clens" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clens_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte)
[]
LowParse.Low.Bytes.clens_vlbytes_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> i: FStar.UInt32.t -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max) LowParse.Bytes.byte
{ "end_col": 81, "end_line": 772, "start_col": 2, "start_line": 771 }
Prims.Tot
val validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 ()
val validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz)) let validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz)) =
false
null
false
validate_total_constant_size (parse_flbytes sz) sz64 ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "FStar.UInt64.t", "Prims.l_and", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt64.n", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "FStar.UInt64.v", "Prims.op_LessThan", "LowParse.Low.Base.validate_total_constant_size", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.validator" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_flbytes (sz: nat) (sz64: U64.t{U64.v sz64 == sz /\ sz < 4294967296}) : Tot (validator (parse_flbytes sz))
[]
LowParse.Low.Bytes.validate_flbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat -> sz64: FStar.UInt64.t{FStar.UInt64.v sz64 == sz /\ sz < 4294967296} -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_flbytes sz)
{ "end_col": 57, "end_line": 23, "start_col": 2, "start_line": 23 }
Prims.Tot
val gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i
val gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) let gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) =
false
null
false
assert (forall x. gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_flbytes_get'", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_flbytes_get", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "Prims.op_LessThanOrEqual", "FStar.Seq.Base.length", "LowParse.Low.Base.Spec.gaccessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
[]
LowParse.Low.Bytes.gaccessor_flbytes_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat{sz < 4294967296} -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_flbytes sz) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_flbytes_get sz i)
{ "end_col": 29, "end_line": 156, "start_col": 2, "start_line": 154 }
Prims.Tot
val write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 ()
val write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) let write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) =
false
null
false
leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "LowParse.Low.Base.leaf_writer_weak_of_strong_constant_size", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Bytes.serialize_flbytes", "LowParse.Low.Bytes.write_flbytes", "LowParse.Low.Base.leaf_writer_weak" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small
false
false
LowParse.Low.Bytes.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 write_flbytes_weak (sz32: U32.t{U32.v sz32 < 4294967295}) : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32)))
[]
LowParse.Low.Bytes.write_flbytes_weak
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz32: FStar.UInt32.t{FStar.UInt32.v sz32 < 4294967295} -> LowParse.Low.Base.leaf_writer_weak (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v sz32) )
{ "end_col": 71, "end_line": 245, "start_col": 2, "start_line": 245 }
Prims.Tot
val jump_all_bytes: Prims.unit -> Tot (jumper parse_all_bytes)
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len
val jump_all_bytes: Prims.unit -> Tot (jumper parse_all_bytes) let jump_all_bytes () : Tot (jumper parse_all_bytes) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_all_bytes h input pos in input.len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.unit", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.jumper" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes ()
false
true
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val jump_all_bytes: Prims.unit -> Tot (jumper parse_all_bytes)
[]
LowParse.Low.Bytes.jump_all_bytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
_: Prims.unit -> LowParse.Low.Base.jumper LowParse.Spec.Bytes.parse_all_bytes
{ "end_col": 11, "end_line": 378, "start_col": 2, "start_line": 375 }
Prims.Tot
val clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); }
val clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) let clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) =
false
null
false
{ clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))) }
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Base.Spec.Mkclens", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "FStar.Bytes.lbytes", "Prims.op_Subtraction", "FStar.Bytes.length", "FStar.Bytes.slice", "LowParse.Low.Base.Spec.clens" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from)))
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clens_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from)))
[]
LowParse.Low.Bytes.clens_vlbytes_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.Spec.clens (LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max) (FStar.Bytes.lbytes (FStar.UInt32.v to - FStar.UInt32.v from))
{ "end_col": 118, "end_line": 691, "start_col": 2, "start_line": 690 }
Prims.Tot
val jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) = jump_synth (jump_bounded_vlgen vmin vmax vk rk serialize_all_bytes ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) ()
val jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) =
false
null
false
jump_synth (jump_bounded_vlgen vmin vmax vk rk serialize_all_bytes) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Low.Base.jumper", "LowParse.Low.Base.leaf_reader", "LowParse.Low.Combinators.jump_synth", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Low.VLGen.jump_bounded_vlgen", "LowParse.Spec.Bytes.parse_bounded_vlgenbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len inline_for_extraction let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) = validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ()) ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk))
[]
LowParse.Low.Bytes.jump_bounded_vlgenbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: LowParse.Spec.DER.der_length_t -> vmax: LowParse.Spec.DER.der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296} -> vk: LowParse.Low.Base.jumper pk -> rk: LowParse.Low.Base.leaf_reader pk -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_bounded_vlgenbytes vmin vmax pk)
{ "end_col": 6, "end_line": 1012, "start_col": 2, "start_line": 1003 }
FStar.Pervasives.Lemma
val valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)]
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos
val valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] =
false
null
true
valid_bounded_vlbytes_elim h min max input pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_bounded_vlbytes_elim", "Prims.unit", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.BoundedInt.log256'", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "Prims.squash", "Prims.eq2", "Prims.int", "LowParse.Low.Base.Spec.content_length", "Prims.op_Addition", "FStar.Bytes.length", "LowParse.Low.Base.Spec.contents", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.Nil" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) ))
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos))) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)]
[]
LowParse.Low.Bytes.valid_bounded_vlbytes_elim_length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos ) (ensures LowParse.Low.Base.Spec.content_length (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos == LowParse.Spec.BoundedInt.log256' max + FStar.Bytes.length (LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos)) [ SMTPat (LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos) ]
{ "end_col": 48, "end_line": 494, "start_col": 2, "start_line": 494 }
Prims.Tot
val accessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i
val accessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) let accessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) =
false
null
false
accessor_vlbytes'_get min max (log256' max) i
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "LowParse.Low.Bytes.accessor_vlbytes'_get", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.accessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_vlbytes_get", "LowParse.Low.Bytes.gaccessor_vlbytes_get" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i))
[]
LowParse.Low.Bytes.accessor_vlbytes_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> i: FStar.UInt32.t -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes_get min max i)
{ "end_col": 47, "end_line": 845, "start_col": 2, "start_line": 845 }
Prims.Tot
val gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to
val gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) let gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) =
false
null
false
assert (forall x. gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_flbytes_slice'", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.op_Subtraction", "LowParse.Low.Bytes.clens_flbytes_slice", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "FStar.Seq.Base.length", "LowParse.Low.Base.Spec.gaccessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } )
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
[]
LowParse.Low.Bytes.gaccessor_flbytes_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat{sz < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_flbytes sz) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_flbytes_slice sz from to)
{ "end_col": 37, "end_line": 101, "start_col": 2, "start_line": 99 }
Prims.Tot
val gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to
val gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) let gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) =
false
null
false
gaccessor_vlbytes'_slice min max (log256' max) from to
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_vlbytes'_slice", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } )
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
[]
LowParse.Low.Bytes.gaccessor_vlbytes_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_vlbytes_slice min max from to)
{ "end_col": 56, "end_line": 730, "start_col": 2, "start_line": 730 }
Prims.Tot
val write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) ()
val write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) =
false
null
false
leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "FStar.UInt32.t", "LowParse.Low.Base.leaf_writer_strong_of_serializer32", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Bytes.serialize_flbytes", "LowParse.Low.Bytes.serialize32_flbytes", "LowParse.Low.Base.leaf_writer_strong" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t)
false
false
LowParse.Low.Bytes.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 write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32)))
[]
LowParse.Low.Bytes.write_flbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz32: FStar.UInt32.t -> LowParse.Low.Base.leaf_writer_strong (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v sz32 ))
{ "end_col": 66, "end_line": 239, "start_col": 2, "start_line": 239 }
Prims.Tot
val accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from
val accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to)) let accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to)) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "Prims.unit", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.op_Subtraction", "LowParse.Low.Bytes.clens_flbytes_slice", "LowParse.Low.Bytes.gaccessor_flbytes_slice", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } )
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_flbytes_slice (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (accessor (gaccessor_flbytes_slice sz from to))
[]
LowParse.Low.Bytes.accessor_flbytes_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat{sz < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_flbytes_slice sz from to)
{ "end_col": 20, "end_line": 112, "start_col": 2, "start_line": 109 }
Prims.Tot
val accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to
val accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) let accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) =
false
null
false
accessor_vlbytes'_slice min max (log256' max) from to
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.accessor_vlbytes'_slice", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.accessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice", "LowParse.Low.Bytes.gaccessor_vlbytes_slice" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_vlbytes_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes_slice min max from to))
[]
LowParse.Low.Bytes.accessor_vlbytes_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes_slice min max from to)
{ "end_col": 55, "end_line": 763, "start_col": 2, "start_line": 763 }
Prims.Tot
val validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) ()
val validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l)) let validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l)) =
false
null
false
validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Low.VLData.validate_bounded_vldata_strong'", "LowParse.Low.Bytes.validate_all_bytes", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "LowParse.Low.Base.validator", "LowParse.Spec.Bytes.parse_bounded_vlbytes'" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (validator (parse_bounded_vlbytes' min max l))
[]
LowParse.Low.Bytes.validate_bounded_vlbytes'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l)
{ "end_col": 6, "end_line": 362, "start_col": 2, "start_line": 359 }
Prims.Tot
val gaccessor_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end)
val gaccessor_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) let gaccessor_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) =
false
null
false
fun (input: bytes) -> (let res = if Seq.length input < U32.v i then (0) else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res)
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Bytes.bytes", "Prims.unit", "FStar.Classical.move_requires", "LowParse.Low.Base.Spec.gaccessor_pre", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_flbytes_get", "LowParse.Low.Base.Spec.gaccessor_post", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Base.parse_strong_prefix", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "Prims.op_Addition", "FStar.Seq.Base.length", "LowParse.Spec.Int.parse_u8_spec'", "Prims._assert", "Prims.eq2", "Prims.int", "Prims.l_or", "Prims.op_GreaterThanOrEqual", "FStar.UInt.size", "FStar.UInt32.n", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.Base.get_parser_kind", "Prims.bool", "LowParse.Low.Base.Spec.gaccessor'" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 1, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "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_flbytes_get' (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i))
[]
LowParse.Low.Bytes.gaccessor_flbytes_get'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat{sz < 4294967296} -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_flbytes sz) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_flbytes_get sz i)
{ "end_col": 6, "end_line": 147, "start_col": 2, "start_line": 130 }
Prims.Tot
val jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) ()
val jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l)) let jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l)) =
false
null
false
jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Combinators.jump_synth", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLData.parse_bounded_vldata_strong'", "LowParse.Low.VLData.jump_bounded_vldata_strong'", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "LowParse.Low.Base.jumper", "LowParse.Spec.Bytes.parse_bounded_vlbytes'" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val jump_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) : Tot (jumper (parse_bounded_vlbytes' min max l))
[]
LowParse.Low.Bytes.jump_bounded_vlbytes'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l)
{ "end_col": 6, "end_line": 389, "start_col": 2, "start_line": 386 }
Prims.Tot
val serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32
val serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) =
false
null
false
fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "FStar.UInt32.t", "FStar.Bytes.lbytes", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "Prims.unit", "LowParse.Low.Bytes.store_bytes", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.serializer32", "LowParse.Spec.Base.total_constant_size_parser_kind", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Bytes.serialize_flbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t)
false
false
LowParse.Low.Bytes.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 serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32)))
[]
LowParse.Low.Bytes.serialize32_flbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz32: FStar.UInt32.t -> LowParse.Low.Base.serializer32 (LowParse.Spec.Bytes.serialize_flbytes (FStar.UInt32.v sz32))
{ "end_col": 6, "end_line": 233, "start_col": 2, "start_line": 231 }
FStar.HyperStack.ST.Stack
val get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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 get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x ))) = let len = bounded_vlgenbytes_payload_length vmin vmax rk input pos in let pos1 = jk input pos in BF.sub input.base pos1 len
val get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x))) let get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x))) =
true
null
false
let len = bounded_vlgenbytes_payload_length vmin vmax rk input pos in let pos1 = jk input pos in BF.sub input.base pos1 len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Low.Base.leaf_reader", "LowParse.Low.Base.jumper", "LowParse.Slice.slice", "LowStar.Buffer.trivial_preorder", "LowParse.Bytes.byte", "FStar.UInt32.t", "LowStar.Buffer.sub", "LowParse.Slice.__proj__Mkslice__item__base", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.buffer", "LowParse.Low.Bytes.bounded_vlgenbytes_payload_length", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlgenbytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.eq2", "Prims.int", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Bytes.length", "LowParse.Low.Base.Spec.get_valid_pos", "LowStar.Buffer.gsub", "FStar.Bytes.len", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowStar.Monotonic.Buffer.as_seq", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len inline_for_extraction let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) = validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ()) ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) = jump_synth (jump_bounded_vlgen vmin vmax vk rk serialize_all_bytes ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x )))) = let h = HST.get () in valid_synth h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes ) (synth_bounded_vlbytes vmin vmax) input pos; valid_bounded_vlgen_elim vmin vmax pk serialize_all_bytes input pos h; let len = rk input pos in let pos1 = Ghost.hide (get_valid_pos pk h input pos) in valid_exact_all_bytes_elim h input (Ghost.reveal pos1) (Ghost.reveal pos1 `U32.add` len); valid_flbytes_elim h (U32.v len) input (Ghost.reveal pos1); len inline_for_extraction let get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x
false
false
LowParse.Low.Bytes.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 get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x)))
[]
LowParse.Low.Bytes.get_bounded_vlgenbytes_contents
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: LowParse.Spec.DER.der_length_t -> vmax: LowParse.Spec.DER.der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296} -> rk: LowParse.Low.Base.leaf_reader pk -> jk: LowParse.Low.Base.jumper pk -> input: LowParse.Slice.slice (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte) (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte) -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack (LowStar.Buffer.buffer LowParse.Bytes.byte)
{ "end_col": 28, "end_line": 1086, "start_col": 1, "start_line": 1084 }
Prims.Tot
val accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length
val accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) let accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) =
false
null
false
accessor_vlbytes' min max (log256' max) length
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "LowParse.Low.Bytes.accessor_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.accessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes", "LowParse.Low.Bytes.gaccessor_vlbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length)))
[]
LowParse.Low.Bytes.accessor_vlbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: FStar.UInt32.t -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes min max (FStar.UInt32.v length))
{ "end_col": 48, "end_line": 681, "start_col": 2, "start_line": 681 }
FStar.HyperStack.ST.Stack
val get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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 get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos
val get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x)) let get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x)) =
true
null
false
get_vlbytes'_contents min max (log256' max) input pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowParse.Low.Bytes.get_vlbytes'_contents", "LowParse.Spec.BoundedInt.log256'", "LowStar.Buffer.buffer", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Bytes.length", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "LowStar.Monotonic.Buffer.mbuffer", "LowStar.Buffer.gsub", "LowParse.Slice.__proj__Mkslice__item__base", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.Bytes.len", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowStar.Monotonic.Buffer.as_seq", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.contents", "LowParse.Spec.BoundedInt.integer_size" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x
false
false
LowParse.Low.Bytes.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 get_vlbytes_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x))
[]
LowParse.Low.Bytes.get_vlbytes_contents
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte )) (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte)) -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack (LowStar.Buffer.buffer LowParse.Bytes.byte)
{ "end_col": 55, "end_line": 586, "start_col": 2, "start_line": 586 }
Prims.Tot
val gaccessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length
val gaccessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) let gaccessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) =
false
null
false
parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x. gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Bytes.gaccessor_vlbytes'_aux", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "FStar.Seq.Base.length", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Low.Base.Spec.gaccessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 6, "max_fuel": 2, "max_ifuel": 6, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "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_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length))
[]
LowParse.Low.Bytes.gaccessor_vlbytes'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> length: Prims.nat{length < 4294967296} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) (LowParse.Spec.Bytes.parse_flbytes length) (LowParse.Low.Bytes.clens_vlbytes min max length)
{ "end_col": 41, "end_line": 643, "start_col": 2, "start_line": 640 }
FStar.Pervasives.Lemma
val valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos
val valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz)))) let valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz)))) =
false
null
true
valid_facts (parse_flbytes sz) h s pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.unit", "Prims.l_and", "Prims.op_LessThanOrEqual", "Prims.op_Addition", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Slice.live_slice", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_flbytes_intro (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
[]
LowParse.Low.Bytes.valid_flbytes_intro
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> sz: Prims.nat{sz < 4294967296} -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires FStar.UInt32.v pos + sz <= FStar.UInt32.v (Mkslice?.len s) /\ LowParse.Slice.live_slice h s) (ensures LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos (FStar.Bytes.hide (LowParse.Low.Base.Spec.bytes_of_slice_from_to h s pos (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))) (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))
{ "end_col": 40, "end_line": 43, "start_col": 2, "start_line": 43 }
Prims.Tot
val validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t{vmax > 0}) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) = validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ()) ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) ()
val validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t{vmax > 0}) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t{vmax > 0}) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) =
false
null
false
validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ())) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "LowParse.Spec.DER.der_length_t", "FStar.UInt32.t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "FStar.UInt32.n", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThanOrEqual", "Prims.op_LessThanOrEqual", "LowParse.Spec.DER.der_length_max", "FStar.UInt32.v", "Prims.op_GreaterThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Low.Base.validator", "LowParse.Low.Base.leaf_reader", "LowParse.Low.Combinators.validate_synth", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Low.VLGen.validate_bounded_vlgen", "LowParse.Low.Bytes.validate_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlgenbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len inline_for_extraction let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t{U32.v min == vmin}) (vmax: der_length_t{vmax > 0}) (max: U32.t{U32.v max == vmax /\ U32.v min <= U32.v max}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk))
[]
LowParse.Low.Bytes.validate_bounded_vlgenbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: LowParse.Spec.DER.der_length_t -> min: FStar.UInt32.t{FStar.UInt32.v min == vmin} -> vmax: LowParse.Spec.DER.der_length_t{vmax > 0} -> max: FStar.UInt32.t{FStar.UInt32.v max == vmax /\ FStar.UInt32.v min <= FStar.UInt32.v max} -> vk: LowParse.Low.Base.validator pk -> rk: LowParse.Low.Base.leaf_reader pk -> LowParse.Low.Base.validator (LowParse.Spec.Bytes.parse_bounded_vlgenbytes vmin vmax pk)
{ "end_col": 6, "end_line": 992, "start_col": 2, "start_line": 980 }
FStar.HyperStack.ST.Stack
val valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos
val valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const))) let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const))) =
true
null
false
let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "FStar.Bytes.bytes", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.buffer_equals_bytes", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "Prims.bool", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.length", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.l_iff", "Prims.eq2", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const)))
[]
LowParse.Low.Bytes.valid_slice_equals_bytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
const: FStar.Bytes.bytes -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool
{ "end_col": 42, "end_line": 342, "start_col": 1, "start_line": 340 }
FStar.Pervasives.Lemma
val valid_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296}) (#sk: parser_kind) (pk: parser sk (bounded_int32 (vmin) (vmax))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (h: HS.mem) : Lemma (requires (valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len))) (ensures (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in let x = BY.hide (bytes_of_slice_from_to h input pos1 (pos1 `U32.add` len)) in valid_content_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos x (pos1 `U32.add` len)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296 } ) (#sk: parser_kind) (pk: parser sk (bounded_int32 (vmin) (vmax))) #rrel #rel (input: slice rrel rel) (pos: U32.t) (h: HS.mem) : Lemma (requires ( valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len ))) (ensures ( let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in let x = BY.hide (bytes_of_slice_from_to h input pos1 (pos1 `U32.add` len)) in valid_content_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos x (pos1 `U32.add` len) )) = let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in valid_flbytes_intro h (U32.v len) input pos1; let pos' = pos1 `U32.add` len in valid_exact_all_bytes_intro h input pos1 pos' ; valid_exact_all_bytes_elim h input pos1 pos' ; valid_bounded_vlgen vmin vmax pk serialize_all_bytes input pos h; valid_synth_intro h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes ) (synth_bounded_vlbytes vmin vmax) input pos
val valid_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296}) (#sk: parser_kind) (pk: parser sk (bounded_int32 (vmin) (vmax))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (h: HS.mem) : Lemma (requires (valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len))) (ensures (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in let x = BY.hide (bytes_of_slice_from_to h input pos1 (pos1 `U32.add` len)) in valid_content_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos x (pos1 `U32.add` len))) let valid_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296}) (#sk: parser_kind) (pk: parser sk (bounded_int32 (vmin) (vmax))) #rrel #rel (input: slice rrel rel) (pos: U32.t) (h: HS.mem) : Lemma (requires (valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len))) (ensures (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in let x = BY.hide (bytes_of_slice_from_to h input pos1 (pos1 `U32.add` len)) in valid_content_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos x (pos1 `U32.add` len))) =
false
null
true
let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in valid_flbytes_intro h (U32.v len) input pos1; let pos' = pos1 `U32.add` len in valid_exact_all_bytes_intro h input pos1 pos'; valid_exact_all_bytes_elim h input pos1 pos'; valid_bounded_vlgen vmin vmax pk serialize_all_bytes input pos h; valid_synth_intro h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes) (synth_bounded_vlbytes vmin vmax) input pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Combinators.valid_synth_intro", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "Prims.unit", "LowParse.Low.VLGen.valid_bounded_vlgen", "LowParse.Low.Bytes.valid_exact_all_bytes_elim", "LowParse.Low.Bytes.valid_exact_all_bytes_intro", "FStar.UInt32.add", "LowParse.Low.Bytes.valid_flbytes_intro", "FStar.UInt32.v", "LowParse.Low.Base.Spec.contents", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Low.Base.Spec.valid", "Prims.op_Addition", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Bytes.parse_bounded_vlgenbytes", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len inline_for_extraction let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) = validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ()) ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) = jump_synth (jump_bounded_vlgen vmin vmax vk rk serialize_all_bytes ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x )))) = let h = HST.get () in valid_synth h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes ) (synth_bounded_vlbytes vmin vmax) input pos; valid_bounded_vlgen_elim vmin vmax pk serialize_all_bytes input pos h; let len = rk input pos in let pos1 = Ghost.hide (get_valid_pos pk h input pos) in valid_exact_all_bytes_elim h input (Ghost.reveal pos1) (Ghost.reveal pos1 `U32.add` len); valid_flbytes_elim h (U32.v len) input (Ghost.reveal pos1); len inline_for_extraction let get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x ))) = let len = bounded_vlgenbytes_payload_length vmin vmax rk input pos in let pos1 = jk input pos in BF.sub input.base pos1 len let valid_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires ( U32.v pos <= U32.v pos' /\ ( let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos ))) (ensures ( valid_exact parse_all_bytes h input pos pos' )) = let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' let valid_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296 } ) (#sk: parser_kind) (pk: parser sk (bounded_int32 (vmin) (vmax))) #rrel #rel (input: slice rrel rel) (pos: U32.t) (h: HS.mem) : Lemma (requires ( valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len ))) (ensures ( let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in let x = BY.hide (bytes_of_slice_from_to h input pos1 (pos1 `U32.add` len)) in valid_content_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos x (pos1 `U32.add` len)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t{vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296}) (#sk: parser_kind) (pk: parser sk (bounded_int32 (vmin) (vmax))) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (h: HS.mem) : Lemma (requires (valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len))) (ensures (let pos1 = get_valid_pos pk h input pos in let len = contents pk h input pos in let x = BY.hide (bytes_of_slice_from_to h input pos1 (pos1 `U32.add` len)) in valid_content_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos x (pos1 `U32.add` len)))
[]
LowParse.Low.Bytes.valid_bounded_vlgenbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: LowParse.Spec.DER.der_length_t -> vmax: LowParse.Spec.DER.der_length_t{vmin <= vmax /\ vmax > 0 /\ vmax < 4294967296} -> pk: LowParse.Spec.Base.parser sk (LowParse.Spec.BoundedInt.bounded_int32 vmin vmax) -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> h: FStar.Monotonic.HyperStack.mem -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid pk h input pos /\ (let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in let len = LowParse.Low.Base.Spec.contents pk h input pos in FStar.UInt32.v pos1 + FStar.UInt32.v len <= FStar.UInt32.v (Mkslice?.len input))) (ensures (let pos1 = LowParse.Low.Base.Spec.get_valid_pos pk h input pos in let len = LowParse.Low.Base.Spec.contents pk h input pos in let x = FStar.Bytes.hide (LowParse.Low.Base.Spec.bytes_of_slice_from_to h input pos1 (FStar.UInt32.add pos1 len)) in LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_bounded_vlgenbytes vmin vmax pk) h input pos x (FStar.UInt32.add pos1 len)))
{ "end_col": 7, "end_line": 1150, "start_col": 1, "start_line": 1132 }
Prims.Tot
val gaccessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i
val gaccessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) let gaccessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) =
false
null
false
Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x. gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "LowParse.Low.Bytes.gaccessor_vlbytes'_get'", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_vlbytes_get", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Seq.Base.length", "FStar.Classical.forall_intro", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "FStar.Pervasives.Native.None", "Prims.op_AmpAmp", "Prims.l_or", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Bytes.hide", "FStar.Seq.Base.slice", "Prims.bool", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Low.Base.Spec.gaccessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t)
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i))
[]
LowParse.Low.Bytes.gaccessor_vlbytes'_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> i: FStar.UInt32.t -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_vlbytes_get min max i)
{ "end_col": 37, "end_line": 812, "start_col": 2, "start_line": 809 }
FStar.Pervasives.Lemma
val valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len
val valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len))) let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len))) =
false
null
true
valid_bounded_vlbytes'_intro h min max (log256' max) input pos len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_bounded_vlbytes'_intro", "LowParse.Spec.BoundedInt.log256'", "Prims.unit", "FStar.UInt32.v", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "Prims.eq2", "LowParse.Low.Base.Spec.contents", "Prims.op_Addition", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "LowParse.Spec.BoundedInt.integer_size", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len)))
[]
LowParse.Low.Bytes.valid_bounded_vlbytes_intro
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> len: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires (let sz = LowParse.Spec.BoundedInt.log256' max in min <= FStar.UInt32.v len /\ FStar.UInt32.v len <= max /\ LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos /\ LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos == len /\ FStar.UInt32.v pos + sz <= 4294967295 /\ (let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len)) h input pos_payload))) (ensures (let sz = LowParse.Spec.BoundedInt.log256' max in let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos (LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len) ) h input pos_payload) (FStar.UInt32.add pos_payload len)))
{ "end_col": 68, "end_line": 904, "start_col": 2, "start_line": 904 }
FStar.HyperStack.ST.Stack
val bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos
val bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x))) let bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x))) =
true
null
false
bounded_vlbytes'_payload_length min max (log256' max) input pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.bounded_vlbytes'_payload_length", "LowParse.Spec.BoundedInt.log256'", "FStar.Monotonic.HyperStack.mem", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "FStar.UInt32.v", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x
false
false
LowParse.Low.Bytes.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 bounded_vlbytes_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t (log256' max))) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t (log256' max))) pos' == BY.reveal x)))
[]
LowParse.Low.Bytes.bounded_vlbytes_payload_length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 65, "end_line": 539, "start_col": 2, "start_line": 539 }
Prims.Tot
val gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end)
val gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) let gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) =
false
null
false
fun (input: bytes) -> (if Seq.length input < sz then (0) else (U32.v from))
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "Prims.l_and", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Bytes.bytes", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.bool", "LowParse.Low.Base.Spec.gaccessor'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.op_Subtraction", "LowParse.Low.Bytes.clens_flbytes_slice" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } )
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_flbytes_slice' (sz: nat{sz < 4294967296}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= sz}) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to))
[]
LowParse.Low.Bytes.gaccessor_flbytes_slice'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat{sz < 4294967296} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= sz} -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_flbytes sz) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_flbytes_slice sz from to)
{ "end_col": 6, "end_line": 92, "start_col": 2, "start_line": 87 }
Prims.Tot
val gaccessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to
val gaccessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) let gaccessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) =
false
null
false
parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x. gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Low.Bytes.gaccessor_vlbytes'_slice_aux", "Prims.unit", "LowParse.Low.Base.Spec.gaccessor_prop_equiv", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice", "Prims._assert", "Prims.l_Forall", "FStar.Seq.Base.seq", "LowParse.Bytes.byte", "Prims.l_imp", "LowParse.Low.Base.Spec.gaccessor_pre", "Prims.op_Addition", "FStar.Seq.Base.length", "FStar.Classical.forall_intro", "LowParse.Bytes.bytes", "LowParse.Spec.Base.parse", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "Prims.eq2", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.tuple2", "LowParse.Spec.Base.consumed_length", "FStar.Pervasives.Native.None", "Prims.op_AmpAmp", "Prims.l_or", "FStar.Pervasives.Native.Some", "FStar.Pervasives.Native.Mktuple2", "FStar.Bytes.hide", "FStar.Seq.Base.slice", "Prims.bool", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Low.Base.Spec.gaccessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } )
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
[]
LowParse.Low.Bytes.gaccessor_vlbytes'_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_vlbytes_slice min max from to)
{ "end_col": 48, "end_line": 722, "start_col": 2, "start_line": 718 }
FStar.HyperStack.ST.Stack
val finalize_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos'))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len
val finalize_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos')) let finalize_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos')) =
true
null
false
finalize_bounded_vlbytes' min max (log256' max) input pos len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.finalize_bounded_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.live_slice", "FStar.UInt32.v", "Prims.op_Addition", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.writable", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "LowParse.Spec.BoundedInt.integer_size", "LowStar.Monotonic.Buffer.modifies", "LowParse.Slice.loc_slice_from_to", "Prims.eq2", "Prims.int", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.uint_to_t" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos'
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finalize_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos'))
[]
LowParse.Low.Bytes.finalize_bounded_vlbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> len: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 63, "end_line": 967, "start_col": 2, "start_line": 967 }
Prims.Tot
val accessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i
val accessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) let accessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in (pos `U32.add` (U32.uint_to_t l)) `U32.add` i
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_vlbytes_get", "LowParse.Low.Bytes.gaccessor_vlbytes'_get", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Low.Base.Spec.valid_facts", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t)
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_vlbytes'_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i))
[]
LowParse.Low.Bytes.accessor_vlbytes'_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> i: FStar.UInt32.t -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes'_get min max l i)
{ "end_col": 43, "end_line": 828, "start_col": 2, "start_line": 821 }
FStar.Pervasives.Lemma
val valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (let sz = l in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)))))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); ()
val valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (let sz = l in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload))))) let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (let sz = l in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload))))) =
false
null
true
valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "LowParse.Low.Bytes.valid_exact_all_bytes_elim", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Low.Base.Spec.contents", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Low.VLData.valid_bounded_vldata_strong'_elim", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Low.Combinators.valid_synth", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes_aux", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "Prims.squash", "FStar.UInt32.v", "Prims.eq2", "Prims.int", "Prims.op_Addition", "LowParse.Low.Base.Spec.content_length", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_pos", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)
false
false
LowParse.Low.Bytes.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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (let sz = l in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)))))
[]
LowParse.Low.Bytes.valid_bounded_vlbytes'_elim
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) h input pos) (ensures (let sz = l in LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos /\ (let len_payload = LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos in min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\ sz + FStar.UInt32.v len_payload == LowParse.Low.Base.Spec.content_length (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) h input pos /\ (let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in let x = LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) h input pos in FStar.Bytes.len x == len_payload /\ LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l ) h input pos (FStar.UInt32.add pos_payload len_payload) /\ LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len_payload)) h input pos_payload x (FStar.UInt32.add pos_payload len_payload)))))
{ "end_col": 4, "end_line": 450, "start_col": 2, "start_line": 444 }
FStar.Pervasives.Lemma
val valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures (let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos'))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos))
val valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures (let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos')) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures (let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos')) =
false
null
true
valid_exact_equiv parse_all_bytes h input pos pos'; contents_exact_eq parse_all_bytes h input pos pos'; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos))
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims._assert", "LowParse.Spec.Base.injective_postcond", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "LowParse.Slice.bytes_of_slice_from", "Prims.unit", "LowParse.Spec.Base.no_lookahead_on", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.int", "Prims.op_Subtraction", "FStar.UInt32.v", "LowParse.Low.Base.Spec.contents_exact_eq", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Low.Base.Spec.valid_exact_equiv", "LowParse.Low.Base.Spec.valid_exact", "Prims.squash", "Prims.l_and", "Prims.eq2", "FStar.Bytes.length", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Low.Base.Spec.contents_exact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos'
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures (let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos'))
[]
LowParse.Low.Bytes.valid_exact_all_bytes_elim
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid_exact LowParse.Spec.Bytes.parse_all_bytes h input pos pos') (ensures (let x = LowParse.Low.Base.Spec.contents_exact LowParse.Spec.Bytes.parse_all_bytes h input pos pos' in let length = FStar.UInt32.v pos' - FStar.UInt32.v pos in FStar.Bytes.length x == length /\ LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes length) h input pos x pos'))
{ "end_col": 128, "end_line": 416, "start_col": 2, "start_line": 411 }
Prims.Tot
val gaccessor_vlbytes'_slice_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end)
val gaccessor_vlbytes'_slice_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) let gaccessor_vlbytes'_slice_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) =
false
null
false
fun (input: bytes) -> (parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) else (l + U32.v from))
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Bytes.bytes", "FStar.Seq.Base.length", "LowParse.Bytes.byte", "Prims.op_Addition", "Prims.bool", "Prims.unit", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Low.Base.Spec.gaccessor'", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } )
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes'_slice_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to))
[]
LowParse.Low.Bytes.gaccessor_vlbytes'_slice_aux
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v to - FStar.UInt32.v from)) (LowParse.Low.Bytes.clens_vlbytes_slice min max from to)
{ "end_col": 6, "end_line": 709, "start_col": 2, "start_line": 703 }
FStar.HyperStack.ST.Stack
val bounded_vlbytes'_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t l)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t l)) pos' == BY.reveal x)) )
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len
val bounded_vlbytes'_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t l)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t l)) pos' == BY.reveal x)) ) let bounded_vlbytes'_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t l)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t l)) pos' == BY.reveal x)) ) =
true
null
false
let h = HST.get () in [@@ inline_let ]let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@@ inline_let ]let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` (U32.uint_to_t l)) in len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "LowParse.Low.Bytes.valid_flbytes_elim", "FStar.UInt32.v", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Low.BoundedInt.read_bounded_integer", "LowParse.Low.Bytes.valid_bounded_vlbytes'_elim", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x
false
false
LowParse.Low.Bytes.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 bounded_vlbytes'_payload_length (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t l)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` (U32.uint_to_t l)) pos' == BY.reveal x)) )
[]
LowParse.Low.Bytes.bounded_vlbytes'_payload_length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 5, "end_line": 519, "start_col": 1, "start_line": 515 }
Prims.Tot
val accessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l
val accessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) let accessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) =
false
null
false
fun #rrel #rel sl pos -> let h = HST.get () in [@@ inline_let ]let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` (U32.uint_to_t l)
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Low.Bytes.valid_bounded_vlbytes'_elim", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes", "LowParse.Low.Bytes.gaccessor_vlbytes'", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 6, "max_fuel": 2, "max_ifuel": 6, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "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": 64, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length)))
[]
LowParse.Low.Bytes.accessor_vlbytes'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> length: FStar.UInt32.t -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes' min max l (FStar.UInt32.v length))
{ "end_col": 31, "end_line": 671, "start_col": 2, "start_line": 663 }
Prims.Tot
val gaccessor_vlbytes'_get' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end)
val gaccessor_vlbytes'_get' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) let gaccessor_vlbytes'_get' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) =
false
null
false
fun (input: bytes) -> (let res = if Seq.length input <= l + U32.v i then (0) else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res)
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "LowParse.Bytes.bytes", "Prims.unit", "FStar.Classical.move_requires", "LowParse.Low.Base.Spec.gaccessor_pre", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_vlbytes_get", "LowParse.Low.Base.Spec.gaccessor_post", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Base.parse_strong_prefix", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "Prims.op_Addition", "FStar.UInt32.v", "FStar.Seq.Base.length", "LowParse.Spec.Int.parse_u8_spec'", "Prims._assert", "Prims.eq2", "Prims.int", "LowParse.Spec.Base.parser_kind_prop_equiv", "LowParse.Spec.Base.get_parser_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "Prims.bool", "LowParse.Low.Base.Spec.gaccessor'" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t)
false
false
LowParse.Low.Bytes.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": 16, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes'_get' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i))
[]
LowParse.Low.Bytes.gaccessor_vlbytes'_get'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> i: FStar.UInt32.t -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_vlbytes_get min max i)
{ "end_col": 6, "end_line": 801, "start_col": 2, "start_line": 783 }
Prims.Tot
val gaccessor_vlbytes'_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end)
val gaccessor_vlbytes'_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) let gaccessor_vlbytes'_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) =
false
null
false
fun (input: bytes) -> (let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res)
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Bytes.bytes", "Prims.unit", "FStar.Classical.move_requires", "LowParse.Low.Base.Spec.gaccessor_pre", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes", "LowParse.Low.Base.Spec.gaccessor_post", "Prims.squash", "Prims.Nil", "FStar.Pervasives.pattern", "LowParse.Spec.Base.parse_strong_prefix", "FStar.Seq.Base.slice", "LowParse.Bytes.byte", "Prims.op_Addition", "FStar.Seq.Base.length", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "Prims.bool", "LowParse.Low.Base.Spec.gaccessor'" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 6, "max_fuel": 2, "max_ifuel": 6, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "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_vlbytes'_aux (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (length: nat{length < 4294967296}) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length))
[]
LowParse.Low.Bytes.gaccessor_vlbytes'_aux
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> length: Prims.nat{length < 4294967296} -> LowParse.Low.Base.Spec.gaccessor' (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) (LowParse.Spec.Bytes.parse_flbytes length) (LowParse.Low.Bytes.clens_vlbytes min max length)
{ "end_col": 6, "end_line": 632, "start_col": 2, "start_line": 619 }
FStar.HyperStack.ST.Stack
val finalize_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos')))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len
val finalize_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos'))) let finalize_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos'))) =
true
null
false
let h0 = HST.get () in [@@ inline_let ]let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@@ inline_let ]let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "FStar.UInt32.add", "Prims.unit", "LowParse.Low.Bytes.valid_bounded_vlbytes'_intro", "LowParse.Low.Bytes.valid_flbytes_intro", "FStar.UInt32.v", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.BoundedInt.write_bounded_integer", "LowParse.Slice.live_slice", "Prims.op_Addition", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.writable", "LowParse.Slice.buffer_srel_of_srel", "LowParse.Slice.__proj__Mkslice__item__base", "LowStar.Monotonic.Buffer.modifies", "LowParse.Slice.loc_slice_from_to", "Prims.eq2", "Prims.int", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Low.Base.Spec.get_valid_pos", "FStar.Bytes.bytes", "LowParse.Low.Base.Spec.contents", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.UInt32.uint_to_t" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos')
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val finalize_bounded_vlbytes' (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h)) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos')))
[]
LowParse.Low.Bytes.finalize_bounded_vlbytes'
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> len: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 27, "end_line": 942, "start_col": 1, "start_line": 933 }
FStar.HyperStack.ST.Stack
val get_vlbytes'_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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 get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len
val get_vlbytes'_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x)) let get_vlbytes'_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x)) =
true
null
false
let h = HST.get () in [@@ inline_let ]let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@@ inline_let ]let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t l)) in BF.sub input.base (pos `U32.add` (U32.uint_to_t l)) len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Slice.slice", "LowParse.Slice.srel_of_buffer_srel", "LowParse.Bytes.byte", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.t", "LowStar.Buffer.sub", "LowParse.Slice.__proj__Mkslice__item__base", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "FStar.Ghost.hide", "LowStar.Monotonic.Buffer.mbuffer", "Prims.unit", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowStar.Buffer.buffer", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Low.BoundedInt.read_bounded_integer", "LowParse.Low.Bytes.valid_bounded_vlbytes'_elim", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "FStar.Bytes.length", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "LowStar.Buffer.gsub", "FStar.Bytes.len", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowStar.Monotonic.Buffer.as_seq", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x
false
false
LowParse.Low.Bytes.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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val get_vlbytes'_contents (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` (U32.uint_to_t l)) (BY.len x) /\ B.as_seq h b == BY.reveal x))
[]
LowParse.Low.Bytes.get_vlbytes'_contents
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> input: LowParse.Slice.slice (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte )) (LowParse.Slice.srel_of_buffer_srel (LowStar.Buffer.trivial_preorder LowParse.Bytes.byte)) -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack (LowStar.Buffer.buffer LowParse.Bytes.byte)
{ "end_col": 55, "end_line": 566, "start_col": 1, "start_line": 561 }
FStar.Pervasives.Lemma
val valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz)
val valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len))) let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len))) =
false
null
true
valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` (U32.uint_to_t sz))
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.UInt32.v", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Low.Base.Spec.valid", "Prims.eq2", "LowParse.Low.Base.Spec.contents", "Prims.op_Addition", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 6, "max_fuel": 2, "max_ifuel": 6, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "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": 128, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (#rrel #rel: _) (input: slice rrel rel) (pos len: U32.t) : Lemma (requires (let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid (parse_flbytes (U32.v len)) h input pos_payload))) (ensures (let sz = l in let pos_payload = pos `U32.add` (U32.uint_to_t sz) in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len)))
[]
LowParse.Low.Bytes.valid_bounded_vlbytes'_intro
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> len: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires (let sz = l in min <= FStar.UInt32.v len /\ FStar.UInt32.v len <= max /\ LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos /\ LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos == len /\ FStar.UInt32.v pos + sz <= 4294967295 /\ (let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len)) h input pos_payload))) (ensures (let sz = l in let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_bounded_vlbytes' min max l) h input pos (LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len) ) h input pos_payload) (FStar.UInt32.add pos_payload len)))
{ "end_col": 82, "end_line": 877, "start_col": 2, "start_line": 873 }
Prims.Tot
val accessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from
val accessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) let accessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in (pos `U32.add` (U32.uint_to_t l)) `U32.add` from
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "Prims.op_GreaterThanOrEqual", "LowParse.Spec.BoundedInt.log256'", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.unit", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes'", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.op_Subtraction", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes_slice", "LowParse.Low.Bytes.gaccessor_vlbytes'_slice", "LowParse.Spec.Bytes.parse_bounded_vlbytes_eq", "LowParse.Slice.bytes_of_slice_from", "LowParse.Low.Base.Spec.valid_facts", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } )
false
false
LowParse.Low.Bytes.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": 50, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_vlbytes'_slice (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (l: nat{l >= log256' max /\ l <= 4}) (from: U32.t) (to: U32.t{U32.v from <= U32.v to /\ U32.v to <= max}) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to))
[]
LowParse.Low.Bytes.accessor_vlbytes'_slice
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> l: Prims.nat{l >= LowParse.Spec.BoundedInt.log256' max /\ l <= 4} -> from: FStar.UInt32.t -> to: FStar.UInt32.t{FStar.UInt32.v from <= FStar.UInt32.v to /\ FStar.UInt32.v to <= max} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_vlbytes'_slice min max l from to)
{ "end_col": 47, "end_line": 752, "start_col": 2, "start_line": 745 }
FStar.Pervasives.Lemma
val valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')]
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos
val valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] let valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] =
false
null
true
valid_facts (parse_flbytes sz) h s pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.unit", "LowParse.Low.Base.Spec.valid_pos", "Prims.squash", "Prims.eq2", "Prims.int", "Prims.op_Addition", "FStar.UInt32.v", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Prims.Nil" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos'))
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_pos_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos pos': U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')]
[]
LowParse.Low.Bytes.valid_pos_flbytes_elim
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> sz: Prims.nat{sz < 4294967296} -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos pos' ) (ensures FStar.UInt32.v pos + sz == FStar.UInt32.v pos') [ SMTPat (LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos pos' ) ]
{ "end_col": 40, "end_line": 55, "start_col": 2, "start_line": 55 }
Prims.Tot
val clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte)
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); }
val clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte) let clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte) =
false
null
false
{ clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)) }
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "FStar.UInt32.t", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.v", "LowParse.Low.Base.Spec.Mkclens", "FStar.Bytes.lbytes", "LowParse.Bytes.byte", "Prims.l_True", "FStar.Bytes.get", "LowParse.Low.Base.Spec.clens" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clens_flbytes_get (sz: nat) (i: U32.t{U32.v i < sz}) : Tot (clens (BY.lbytes sz) byte)
[]
LowParse.Low.Bytes.clens_flbytes_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.Spec.clens (FStar.Bytes.lbytes sz) LowParse.Bytes.byte
{ "end_col": 62, "end_line": 122, "start_col": 2, "start_line": 121 }
Prims.GTot
val clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length
val clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 let clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 =
false
null
false
BY.length x == length
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "sometrivial" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "Prims.eq2", "Prims.int", "Prims.l_or", "FStar.UInt.size", "Prims.op_GreaterThanOrEqual", "FStar.Bytes.length" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val clens_vlbytes_cond (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0
[]
LowParse.Low.Bytes.clens_vlbytes_cond
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: Prims.nat -> x: LowParse.Spec.Bytes.parse_bounded_vlbytes_t min max -> Prims.GTot Type0
{ "end_col": 23, "end_line": 598, "start_col": 2, "start_line": 598 }
Prims.Tot
val accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i
val accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i)) let accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i)) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "FStar.UInt32.t", "FStar.UInt32.v", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.add", "Prims.unit", "LowParse.Low.Base.Spec.slice_access_eq", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_flbytes_get", "LowParse.Low.Bytes.gaccessor_flbytes_get", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.accessor" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val accessor_flbytes_get (sz: nat{sz < 4294967296}) (i: U32.t{U32.v i < sz}) : Tot (accessor (gaccessor_flbytes_get sz i))
[]
LowParse.Low.Bytes.accessor_flbytes_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
sz: Prims.nat{sz < 4294967296} -> i: FStar.UInt32.t{FStar.UInt32.v i < sz} -> LowParse.Low.Base.accessor (LowParse.Low.Bytes.gaccessor_flbytes_get sz i)
{ "end_col": 17, "end_line": 166, "start_col": 2, "start_line": 163 }
FStar.HyperStack.ST.Stack
val buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) ))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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 buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res
val buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) =
true
null
false
let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@@ inline_let ]let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ (let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> (Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i)) `Seq.equal` (Seq.slice (BY.reveal const) 0 i))) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else let i' = i `U32.add` 1ul in [@@ inline_let ]let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert ((Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i')) `Seq.equal` (Seq.snoc s1 c1)); assert ((Seq.slice (BY.reveal const) 0 (U32.v i')) `Seq.equal` (Seq.snoc s2 c2)); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res); let res = B.index bres 0ul in HST.pop_frame (); res
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "FStar.Bytes.bytes", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.UInt32.t", "Prims.bool", "Prims.unit", "FStar.HyperStack.ST.pop_frame", "LowStar.Monotonic.Buffer.index", "LowStar.Buffer.trivial_preorder", "FStar.UInt32.__uint_to_t", "C.Loops.do_while", "Prims.op_Equality", "Prims.op_Negation", "LowStar.Monotonic.Buffer.upd", "FStar.UInt8.t", "FStar.Bytes.get", "FStar.UInt32.add", "FStar.Classical.move_requires", "FStar.Seq.Base.equal", "FStar.Seq.Properties.snoc", "Prims.l_and", "Prims.eq2", "FStar.Seq.Properties.lemma_snoc_inj", "Prims._assert", "FStar.Bytes.byte", "FStar.Seq.Base.slice", "FStar.Bytes.reveal", "FStar.UInt32.v", "LowStar.Monotonic.Buffer.as_seq", "Prims.op_Addition", "FStar.Bytes.index", "FStar.Seq.Base.seq", "LowStar.Monotonic.Buffer.get", "FStar.Monotonic.HyperStack.mem", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_buffer", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.l_imp", "FStar.UInt.uint_t", "FStar.UInt32.n", "Prims.l_iff", "FStar.Seq.Base.index", "FStar.HyperStack.ST.get", "Prims.nat", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.Bytes.len", "FStar.HyperStack.ST.push_frame", "LowStar.Monotonic.Buffer.live", "FStar.Bytes.length", "LowStar.Monotonic.Buffer.loc_none" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const)
false
false
LowParse.Low.Bytes.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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b)) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) ))
[]
LowParse.Low.Bytes.buffer_equals_bytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
const: FStar.Bytes.bytes -> b: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.bool
{ "end_col": 5, "end_line": 322, "start_col": 1, "start_line": 278 }
Prims.Tot
val jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max)
val jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max)) let jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max)) =
false
null
false
jump_bounded_vlbytes' min max (log256' max)
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Bytes.jump_bounded_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.jumper", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val jump_bounded_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) : Tot (jumper (parse_bounded_vlbytes min max))
[]
LowParse.Low.Bytes.jump_bounded_vlbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> LowParse.Low.Base.jumper (LowParse.Spec.Bytes.parse_bounded_vlbytes min max)
{ "end_col": 45, "end_line": 396, "start_col": 2, "start_line": 396 }
Prims.Tot
val gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) )
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length
val gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) ) let gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) ) =
false
null
false
gaccessor_vlbytes' min max (log256' max) length
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Low.Bytes.gaccessor_vlbytes'", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Bytes.clens_vlbytes" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } )
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (length: nat{length < 4294967296}) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length) )
[]
LowParse.Low.Bytes.gaccessor_vlbytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> length: Prims.nat{length < 4294967296} -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) (LowParse.Spec.Bytes.parse_flbytes length) (LowParse.Low.Bytes.clens_vlbytes min max length)
{ "end_col": 49, "end_line": 652, "start_col": 2, "start_line": 652 }
Prims.Tot
val gaccessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i
val gaccessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) let gaccessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) =
false
null
false
gaccessor_vlbytes'_get min max (log256' max) i
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "FStar.UInt32.t", "LowParse.Low.Bytes.gaccessor_vlbytes'_get", "LowParse.Spec.BoundedInt.log256'", "LowParse.Low.Base.Spec.gaccessor", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "LowParse.Spec.Int.parse_u8_kind", "FStar.UInt8.t", "LowParse.Spec.Int.parse_u8", "LowParse.Low.Bytes.clens_vlbytes_get" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val gaccessor_vlbytes_get (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i))
[]
LowParse.Low.Bytes.gaccessor_vlbytes_get
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> i: FStar.UInt32.t -> LowParse.Low.Base.Spec.gaccessor (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) LowParse.Spec.Int.parse_u8 (LowParse.Low.Bytes.clens_vlbytes_get min max i)
{ "end_col": 48, "end_line": 837, "start_col": 2, "start_line": 837 }
Prims.Tot
val validate_all_bytes: Prims.unit -> Tot (validator parse_all_bytes)
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len
val validate_all_bytes: Prims.unit -> Tot (validator parse_all_bytes) let validate_all_bytes () : Tot (validator parse_all_bytes) =
false
null
false
fun #rrel #rel input pos -> let h = HST.get () in [@@ inline_let ]let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "total" ]
[ "Prims.unit", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt64.t", "FStar.Int.Cast.uint32_to_uint64", "LowParse.Slice.__proj__Mkslice__item__len", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Low.ErrorCode.uint64_to_uint32", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.validator" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes ()
false
true
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val validate_all_bytes: Prims.unit -> Tot (validator parse_all_bytes)
[]
LowParse.Low.Bytes.validate_all_bytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
_: Prims.unit -> LowParse.Low.Base.validator LowParse.Spec.Bytes.parse_all_bytes
{ "end_col": 33, "end_line": 351, "start_col": 2, "start_line": 348 }
FStar.Pervasives.Lemma
val valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos
val valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz)))) let valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz)))) =
false
null
true
valid_flbytes_intro h sz s pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.b2t", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_flbytes_intro", "Prims.unit", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "Prims.squash", "LowParse.Low.Base.Spec.valid_content_pos", "FStar.Bytes.hide", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.UInt32.add", "FStar.UInt32.uint_to_t", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_flbytes_elim (h: HS.mem) (sz: nat{sz < 4294967296}) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures (valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` (U32.uint_to_t sz)))) (pos `U32.add` (U32.uint_to_t sz))))
[]
LowParse.Low.Bytes.valid_flbytes_elim
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> sz: Prims.nat{sz < 4294967296} -> s: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_flbytes sz) h s pos) (ensures LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes sz) h s pos (FStar.Bytes.hide (LowParse.Low.Base.Spec.bytes_of_slice_from_to h s pos (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))) (FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz)))
{ "end_col": 32, "end_line": 68, "start_col": 2, "start_line": 68 }
FStar.Pervasives.Lemma
val valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)))))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos
val valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload))))) let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload))))) =
false
null
true
valid_bounded_vlbytes'_elim h min max (log256' max) input pos
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "Prims.nat", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "Prims.op_GreaterThan", "Prims.op_LessThan", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Bytes.valid_bounded_vlbytes'_elim", "LowParse.Spec.BoundedInt.log256'", "Prims.unit", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.VLData.parse_bounded_vldata_strong_kind", "LowParse.Spec.Bytes.parse_all_bytes_kind", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes", "Prims.squash", "LowParse.Spec.BoundedInt.parse_bounded_integer_kind", "LowParse.Spec.BoundedInt.bounded_integer", "LowParse.Spec.BoundedInt.parse_bounded_integer", "FStar.UInt32.v", "Prims.eq2", "Prims.int", "Prims.op_Addition", "LowParse.Low.Base.Spec.content_length", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_pos", "FStar.UInt32.add", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.Spec.contents", "FStar.UInt32.uint_to_t", "LowParse.Spec.BoundedInt.integer_size", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat{min <= max /\ max > 0 /\ max < 4294967296}) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_bounded_vlbytes min max) h input pos)) (ensures (let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ (let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ (let pos_payload = pos `U32.add` (U32.uint_to_t sz) in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload)))))
[]
LowParse.Low.Bytes.valid_bounded_vlbytes_elim
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> min: Prims.nat -> max: Prims.nat{min <= max /\ max > 0 /\ max < 4294967296} -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.Pervasives.Lemma (requires LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos ) (ensures (let sz = LowParse.Spec.BoundedInt.log256' max in LowParse.Low.Base.Spec.valid (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos /\ (let len_payload = LowParse.Low.Base.Spec.contents (LowParse.Spec.BoundedInt.parse_bounded_integer sz) h input pos in min <= FStar.UInt32.v len_payload /\ FStar.UInt32.v len_payload <= max /\ sz + FStar.UInt32.v len_payload == LowParse.Low.Base.Spec.content_length (LowParse.Spec.Bytes.parse_bounded_vlbytes min max ) h input pos /\ (let pos_payload = FStar.UInt32.add pos (FStar.UInt32.uint_to_t sz) in let x = LowParse.Low.Base.Spec.contents (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos in FStar.Bytes.len x == len_payload /\ LowParse.Low.Base.Spec.valid_pos (LowParse.Spec.Bytes.parse_bounded_vlbytes min max) h input pos (FStar.UInt32.add pos_payload len_payload) /\ LowParse.Low.Base.Spec.valid_content_pos (LowParse.Spec.Bytes.parse_flbytes (FStar.UInt32.v len_payload)) h input pos_payload x (FStar.UInt32.add pos_payload len_payload)))))
{ "end_col": 63, "end_line": 477, "start_col": 2, "start_line": 477 }
FStar.Pervasives.Lemma
val valid_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (U32.v pos <= U32.v pos' /\ (let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos))) (ensures (valid_exact parse_all_bytes h input pos pos'))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires ( U32.v pos <= U32.v pos' /\ ( let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos ))) (ensures ( valid_exact parse_all_bytes h input pos pos' )) = let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos'
val valid_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (U32.v pos <= U32.v pos' /\ (let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos))) (ensures (valid_exact parse_all_bytes h input pos pos')) let valid_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (U32.v pos <= U32.v pos' /\ (let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos))) (ensures (valid_exact parse_all_bytes h input pos pos')) =
false
null
true
let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); valid_exact_equiv parse_all_bytes h input pos pos'; contents_exact_eq parse_all_bytes h input pos pos'
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[ "lemma" ]
[ "FStar.Monotonic.HyperStack.mem", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "LowParse.Low.Base.Spec.contents_exact_eq", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "Prims.unit", "LowParse.Low.Base.Spec.valid_exact_equiv", "Prims._assert", "LowParse.Spec.Base.injective_postcond", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "LowParse.Slice.bytes_of_slice_from", "LowParse.Spec.Base.no_lookahead_on", "LowParse.Low.Base.Spec.valid_facts", "LowParse.Spec.Base.total_constant_size_parser_kind", "Prims.int", "Prims.op_Subtraction", "FStar.UInt32.v", "Prims.l_and", "Prims.b2t", "Prims.op_LessThanOrEqual", "LowParse.Low.Base.Spec.valid", "Prims.squash", "LowParse.Low.Base.Spec.valid_exact", "Prims.Nil", "FStar.Pervasives.pattern" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len inline_for_extraction let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) = validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ()) ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) = jump_synth (jump_bounded_vlgen vmin vmax vk rk serialize_all_bytes ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x )))) = let h = HST.get () in valid_synth h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes ) (synth_bounded_vlbytes vmin vmax) input pos; valid_bounded_vlgen_elim vmin vmax pk serialize_all_bytes input pos h; let len = rk input pos in let pos1 = Ghost.hide (get_valid_pos pk h input pos) in valid_exact_all_bytes_elim h input (Ghost.reveal pos1) (Ghost.reveal pos1 `U32.add` len); valid_flbytes_elim h (U32.v len) input (Ghost.reveal pos1); len inline_for_extraction let get_bounded_vlgenbytes_contents (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (jk: jumper pk) (input: slice (BF.trivial_preorder _) (BF.trivial_preorder _)) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in B.modifies B.loc_none h h' /\ U32.v pos1 + BY.length x == U32.v (get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos) /\ b == BF.gsub input.base pos1 (BY.len x) /\ B.as_seq h b == BY.reveal x ))) = let len = bounded_vlgenbytes_payload_length vmin vmax rk input pos in let pos1 = jk input pos in BF.sub input.base pos1 len let valid_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires ( U32.v pos <= U32.v pos' /\ ( let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos ))) (ensures ( valid_exact parse_all_bytes h input pos pos'
false
false
LowParse.Low.Bytes.fst
{ "detail_errors": false, "detail_hint_replay": false, "initial_fuel": 2, "initial_ifuel": 1, "max_fuel": 8, "max_ifuel": 2, "no_plugins": false, "no_smt": false, "no_tactics": false, "quake_hi": 1, "quake_keep": false, "quake_lo": 1, "retry": false, "reuse_hint_for": null, "smtencoding_elim_box": false, "smtencoding_l_arith_repr": "boxwrap", "smtencoding_nl_arith_repr": "boxwrap", "smtencoding_valid_elim": false, "smtencoding_valid_intro": true, "tcnorm": true, "trivial_pre_for_unannotated_effectful_fns": true, "z3cliopt": [], "z3refresh": false, "z3rlimit": 5, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val valid_exact_all_bytes_intro (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos': U32.t) : Lemma (requires (U32.v pos <= U32.v pos' /\ (let length = U32.v pos' - U32.v pos in valid (parse_flbytes length) h input pos))) (ensures (valid_exact parse_all_bytes h input pos pos'))
[]
LowParse.Low.Bytes.valid_exact_all_bytes_intro
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
h: FStar.Monotonic.HyperStack.mem -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> pos': FStar.UInt32.t -> FStar.Pervasives.Lemma (requires FStar.UInt32.v pos <= FStar.UInt32.v pos' /\ (let length = FStar.UInt32.v pos' - FStar.UInt32.v pos in LowParse.Low.Base.Spec.valid (LowParse.Spec.Bytes.parse_flbytes length) h input pos)) (ensures LowParse.Low.Base.Spec.valid_exact LowParse.Spec.Bytes.parse_all_bytes h input pos pos')
{ "end_col": 52, "end_line": 1108, "start_col": 1, "start_line": 1102 }
FStar.HyperStack.ST.Stack
val bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x))))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x )))) = let h = HST.get () in valid_synth h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes ) (synth_bounded_vlbytes vmin vmax) input pos; valid_bounded_vlgen_elim vmin vmax pk serialize_all_bytes input pos h; let len = rk input pos in let pos1 = Ghost.hide (get_valid_pos pk h input pos) in valid_exact_all_bytes_elim h input (Ghost.reveal pos1) (Ghost.reveal pos1 `U32.add` len); valid_flbytes_elim h (U32.v len) input (Ghost.reveal pos1); len
val bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x)))) let bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x)))) =
true
null
false
let h = HST.get () in valid_synth h (parse_bounded_vlgen vmin vmax pk serialize_all_bytes) (synth_bounded_vlbytes vmin vmax) input pos; valid_bounded_vlgen_elim vmin vmax pk serialize_all_bytes input pos h; let len = rk input pos in let pos1 = Ghost.hide (get_valid_pos pk h input pos) in valid_exact_all_bytes_elim h input (Ghost.reveal pos1) ((Ghost.reveal pos1) `U32.add` len); valid_flbytes_elim h (U32.v len) input (Ghost.reveal pos1); len
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "LowParse.Spec.DER.der_length_t", "Prims.l_and", "Prims.b2t", "Prims.op_GreaterThan", "Prims.op_LessThanOrEqual", "Prims.op_LessThan", "LowParse.Spec.Base.parser_kind", "LowParse.Spec.Base.parser", "LowParse.Spec.BoundedInt.bounded_int32", "LowParse.Low.Base.leaf_reader", "LowParse.Slice.srel", "LowParse.Bytes.byte", "LowParse.Slice.slice", "FStar.UInt32.t", "Prims.unit", "LowParse.Low.Bytes.valid_flbytes_elim", "FStar.UInt32.v", "FStar.Ghost.reveal", "LowParse.Low.Bytes.valid_exact_all_bytes_elim", "FStar.UInt32.add", "FStar.Ghost.erased", "FStar.Ghost.hide", "LowParse.Low.Base.Spec.get_valid_pos", "LowParse.Low.VLGen.valid_bounded_vlgen_elim", "LowParse.Spec.Bytes.parse_all_bytes_kind", "FStar.Bytes.bytes", "LowParse.Spec.Bytes.parse_all_bytes", "LowParse.Spec.Bytes.serialize_all_bytes", "LowParse.Low.Combinators.valid_synth", "LowParse.Spec.VLGen.parse_bounded_vlgen_kind", "LowParse.Spec.VLData.parse_bounded_vldata_strong_t", "LowParse.Spec.Bytes.parse_bounded_vlbytes_t", "LowParse.Spec.VLGen.parse_bounded_vlgen", "LowParse.Spec.Bytes.synth_bounded_vlbytes", "FStar.Monotonic.HyperStack.mem", "FStar.HyperStack.ST.get", "LowParse.Low.Base.Spec.valid", "LowParse.Spec.Bytes.parse_bounded_vlgenbytes", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_none", "Prims.op_Addition", "LowParse.Slice.__proj__Mkslice__item__len", "Prims.eq2", "FStar.Bytes.len", "LowParse.Low.Base.Spec.valid_content_pos", "LowParse.Spec.Base.total_constant_size_parser_kind", "FStar.Bytes.lbytes", "LowParse.Spec.Bytes.parse_flbytes", "FStar.Seq.Base.seq", "FStar.Bytes.byte", "LowParse.Low.Base.Spec.bytes_of_slice_from_to", "FStar.Bytes.reveal", "LowParse.Low.Base.Spec.contents" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame () #pop-options inline_for_extraction let serialize32_flbytes (sz32: U32.t) : Tot (serializer32 (serialize_flbytes (U32.v sz32))) = fun (x: BY.lbytes (U32.v sz32)) #rrel #rel b pos -> let _ = store_bytes x 0ul sz32 b pos in sz32 inline_for_extraction let write_flbytes (sz32: U32.t) : Tot (leaf_writer_strong (serialize_flbytes (U32.v sz32))) = leaf_writer_strong_of_serializer32 (serialize32_flbytes sz32) () inline_for_extraction let write_flbytes_weak (sz32: U32.t { U32.v sz32 < 4294967295 } ) // need to return that value if output buffer is too small : Tot (leaf_writer_weak (serialize_flbytes (U32.v sz32))) = leaf_writer_weak_of_strong_constant_size (write_flbytes sz32) sz32 () (* // TODO: remove, since nobody is using this inline_for_extraction let read_flbytes (sz32: U32.t) : Tot (leaf_reader (parse_flbytes (U32.v sz32))) = fun input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v sz32)) h input pos in BY.of_buffer sz32 (B.sub input.base pos sz32) *) (* Equality test between a vlbytes and a constant lbytes *) #push-options "--z3rlimit 32" inline_for_extraction let buffer_equals_bytes (const: BY.bytes) (#rrel #rel: _) (b: B.mbuffer byte rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> B.live h b /\ U32.v pos + BY.length const <= B.length b )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + BY.length const) == BY.reveal const) )) = let h0 = HST.get () in HST.push_frame (); let len = BY.len const in let bi = BF.alloca 0ul 1ul in let bres = BF.alloca true 1ul in let h1 = HST.get () in [@inline_let] let inv (h: HS.mem) (stop: bool) : GTot Type0 = B.modifies (B.loc_union (B.loc_buffer bi) (B.loc_buffer bres)) h1 h /\ ( let length = U32.v len in let i32 = (Seq.index (B.as_seq h bi) 0) in let i = U32.v i32 in let res = Seq.index (B.as_seq h bres) 0 in i <= length /\ (stop == false ==> res == true) /\ ((stop == true /\ res == true) ==> i == length) /\ (res == true <==> Seq.slice (B.as_seq h b) (U32.v pos) (U32.v pos + i) `Seq.equal` Seq.slice (BY.reveal const) 0 i) ) in C.Loops.do_while inv (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let i' = i `U32.add` 1ul in [@inline_let] let _ = let s1 = (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i)) in let c1 = (B.get h0 b (U32.v pos + U32.v i)) in let s2 = (Seq.slice (BY.reveal const) 0 (U32.v i)) in let c2 = (BY.index const (U32.v i)) in assert (Seq.slice (B.as_seq h0 b) (U32.v pos) (U32.v pos + U32.v i') `Seq.equal` Seq.snoc s1 c1); assert (Seq.slice (BY.reveal const) 0 (U32.v i') `Seq.equal` Seq.snoc s2 c2); Classical.move_requires (Seq.lemma_snoc_inj s1 s2 c1) c2 in let res = B.index b (pos `U32.add` i) = BY.get const i in B.upd bres 0ul res; B.upd bi 0ul i'; not res end ); let res = B.index bres 0ul in HST.pop_frame (); res #pop-options inline_for_extraction let valid_slice_equals_bytes (const: BY.bytes) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack bool (requires (fun h -> valid (parse_flbytes (BY.length const)) h input pos )) (ensures (fun h res h' -> B.modifies B.loc_none h h' /\ (res == true <==> contents (parse_flbytes (BY.length const)) h input pos == const ))) = let h = HST.get () in [@inline_let] let _ = valid_facts (parse_flbytes (BY.length const)) h input pos in buffer_equals_bytes const input.base pos inline_for_extraction let validate_all_bytes () : Tot (validator parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input (uint64_to_uint32 pos) in Cast.uint32_to_uint64 input.len inline_for_extraction let validate_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (validator (parse_bounded_vlbytes' min max l)) = validate_synth (validate_bounded_vldata_strong' min max l serialize_all_bytes (validate_all_bytes ())) (synth_bounded_vlbytes min max) () inline_for_extraction let validate_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (validator (parse_bounded_vlbytes min max)) = validate_bounded_vlbytes' min max (log256' max) inline_for_extraction let jump_all_bytes () : Tot (jumper parse_all_bytes) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts parse_all_bytes h input pos in input.len inline_for_extraction let jump_bounded_vlbytes' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) : Tot (jumper (parse_bounded_vlbytes' min max l)) = jump_synth (jump_bounded_vldata_strong' min max l serialize_all_bytes) (synth_bounded_vlbytes min max) () inline_for_extraction let jump_bounded_vlbytes (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) : Tot (jumper (parse_bounded_vlbytes min max)) = jump_bounded_vlbytes' min max (log256' max) let valid_exact_all_bytes_elim (h: HS.mem) (#rrel #rel: _) (input: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_exact parse_all_bytes h input pos pos')) (ensures ( let x = contents_exact parse_all_bytes h input pos pos' in let length = U32.v pos' - U32.v pos in BY.length x == length /\ valid_content_pos (parse_flbytes length) h input pos x pos' )) = valid_exact_equiv parse_all_bytes h input pos pos' ; contents_exact_eq parse_all_bytes h input pos pos' ; let length = U32.v pos' - U32.v pos in valid_facts (parse_flbytes length) h input pos ; assert (no_lookahead_on (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)); assert (injective_postcond (parse_flbytes length) (bytes_of_slice_from_to h input pos pos') (bytes_of_slice_from h input pos)) #push-options "--z3rlimit 32" let valid_bounded_vlbytes'_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes' min max l) h input pos )) (ensures ( let sz = l in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes' min max l) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes' min max l) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_synth h (parse_bounded_vlbytes_aux min max l) (synth_bounded_vlbytes min max) input pos; valid_bounded_vldata_strong'_elim h min max l serialize_all_bytes input pos; let sz = l in let len_payload = contents (parse_bounded_integer sz) h input pos in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_exact_all_bytes_elim h input pos_payload (pos_payload `U32.add` len_payload); () #pop-options let valid_bounded_vlbytes_elim (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( let sz = log256' max in valid (parse_bounded_integer sz) h input pos /\ ( let len_payload = contents (parse_bounded_integer sz) h input pos in min <= U32.v len_payload /\ U32.v len_payload <= max /\ sz + U32.v len_payload == content_length (parse_bounded_vlbytes min max) h input pos /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in let x = contents (parse_bounded_vlbytes min max) h input pos in BY.len x == len_payload /\ valid_pos (parse_bounded_vlbytes min max) h input pos (pos_payload `U32.add` len_payload) /\ valid_content_pos (parse_flbytes (U32.v len_payload)) h input pos_payload x (pos_payload `U32.add` len_payload) )))) = valid_bounded_vlbytes'_elim h min max (log256' max) input pos let valid_bounded_vlbytes_elim_length (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : Lemma (requires ( valid (parse_bounded_vlbytes min max) h input pos )) (ensures ( content_length (parse_bounded_vlbytes min max) h input pos == log256' max + BY.length (contents (parse_bounded_vlbytes min max) h input pos) )) [SMTPat (valid (parse_bounded_vlbytes min max) h input pos)] = valid_bounded_vlbytes_elim h min max input pos inline_for_extraction let bounded_vlbytes'_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + l + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes' min max l) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes' min max l) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t l) pos' == BY.reveal x ))) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_flbytes_elim h (U32.v len) input (pos `U32.add` U32.uint_to_t l) in len inline_for_extraction let bounded_vlbytes_payload_length (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ U32.v pos + log256' max + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlbytes min max) h input pos in let pos' = get_valid_pos (parse_bounded_vlbytes min max) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t (log256' max)) x pos' /\ bytes_of_slice_from_to h input (pos `U32.add` U32.uint_to_t (log256' max)) pos' == BY.reveal x ))) = bounded_vlbytes'_payload_length min max (log256' max) input pos (* Get the content buffer (with trivial buffers only, not generalizable to monotonicity) *) #push-options "--z3rlimit 32" inline_for_extraction let get_vlbytes'_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes' min max l) h input pos)) (ensures (fun h b h' -> let x = contents (parse_bounded_vlbytes' min max l) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = let h = HST.get () in [@inline_let] let _ = valid_bounded_vlbytes'_elim h min max l input pos in let len = read_bounded_integer l input pos in [@inline_let] let _ = valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t l) in BF.sub input.base (pos `U32.add` U32.uint_to_t l) len #pop-options inline_for_extraction let get_vlbytes_contents (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (input: slice (srel_of_buffer_srel (BF.trivial_preorder _)) (srel_of_buffer_srel (BF.trivial_preorder _))) (pos: U32.t) : HST.Stack (BF.buffer byte) (requires (fun h -> valid (parse_bounded_vlbytes min max) h input pos)) (ensures (fun h b h' -> let l = log256' max in let x = contents (parse_bounded_vlbytes min max) h input pos in B.modifies B.loc_none h h' /\ U32.v pos + l + BY.length x <= U32.v input.len /\ b == BF.gsub input.base (pos `U32.add` U32.uint_to_t l) (BY.len x) /\ B.as_seq h b == BY.reveal x )) = get_vlbytes'_contents min max (log256' max) input pos (* In fact, the following accessors are not useful in practice, because users would need to have the flbytes parser combinator in their scope *) let clens_vlbytes_cond (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) (x: parse_bounded_vlbytes_t min max) : GTot Type0 = BY.length x == length let clens_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes length)) = { clens_cond = (clens_vlbytes_cond min max length); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (x <: Ghost (BY.lbytes length) (requires (clens_vlbytes_cond min max length x)) (ensures (fun _ -> True)))); } #push-options "--z3rlimit 16 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let gaccessor_vlbytes'_aux (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = fun (input: bytes) -> (begin let res = if Seq.length input >= l then (l) else (0) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) input res)) = parse_bounded_vlbytes_eq min max l input; parse_strong_prefix (parse_flbytes length) (Seq.slice input l (l + length)) (Seq.slice input l (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) x ==> Seq.length x >= l); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes length) (clens_vlbytes min max length) (gaccessor_vlbytes'_aux min max l length); gaccessor_vlbytes'_aux min max l length #pop-options let gaccessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: nat { length < 4294967296 } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes length) (clens_vlbytes min max length)) = gaccessor_vlbytes' min max (log256' max) length #push-options "--z3rlimit 64 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" inline_for_extraction let accessor_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes' min max l (U32.v length))) = fun #rrel #rel sl pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_vlbytes' min max l (U32.v length)) sl pos; valid_bounded_vlbytes'_elim h min max l sl pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h sl pos) in pos `U32.add` U32.uint_to_t l #pop-options inline_for_extraction let accessor_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (length: U32.t) : Tot (accessor (gaccessor_vlbytes min max (U32.v length))) = accessor_vlbytes' min max (log256' max) length let clens_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (clens (parse_bounded_vlbytes_t min max) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v to <= BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_slice_aux (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = fun (input: bytes) -> ( begin parse_bounded_vlbytes_eq min max l input; if Seq.length input < l + U32.v to then (0) // dummy else (l + U32.v from) end) let gaccessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = parser_kind_prop_equiv (parse_bounded_vldata_strong_kind min max l parse_all_bytes_kind) (parse_bounded_vlbytes' min max l); Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) x ==> l + U32.v to <= Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to) (gaccessor_vlbytes'_slice_aux min max l from to); gaccessor_vlbytes'_slice_aux min max l from to let gaccessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_flbytes (U32.v to - U32.v from)) (clens_vlbytes_slice min max from to)) = gaccessor_vlbytes'_slice min max (log256' max) from to #pop-options #push-options "--z3rlimit 50" inline_for_extraction let accessor_vlbytes'_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes'_slice min max l from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_slice min max l from to) input pos in pos `U32.add` U32.uint_to_t l `U32.add` from #pop-options inline_for_extraction let accessor_vlbytes_slice (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= max } ) : Tot (accessor (gaccessor_vlbytes_slice min max from to)) = accessor_vlbytes'_slice min max (log256' max) from to let clens_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (clens (parse_bounded_vlbytes_t min max) byte) = { clens_cond = (fun (x: parse_bounded_vlbytes_t min max) -> U32.v i < BY.length x); clens_get = (fun (x: parse_bounded_vlbytes_t min max) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16" let gaccessor_vlbytes'_get' (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor' (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = fun (input: bytes) -> ( begin let res = if Seq.length input <= l + U32.v i then (0) // dummy else (l + U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input)) (ensures (gaccessor_post (parse_bounded_vlbytes' min max l) parse_u8 (clens_vlbytes_get min max i) input res)) = parse_bounded_vlbytes_eq min max l input; parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (l + U32.v i)); parse_u8_spec' (Seq.slice input (l + U32.v i) (l + U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (l + U32.v i) (l + U32.v i + 1)) (Seq.slice input (l + U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) let gaccessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i)) = Classical.forall_intro (parse_bounded_vlbytes_eq min max l); assert (forall x . gaccessor_pre (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) x ==> l + U32.v i < Seq.length x); gaccessor_prop_equiv (parse_bounded_vlbytes' min max l) (parse_u8) (clens_vlbytes_get min max i) (gaccessor_vlbytes'_get' min max l i); gaccessor_vlbytes'_get' min max l i inline_for_extraction let accessor_vlbytes'_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes'_get min max l i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); slice_access_eq h (gaccessor_vlbytes'_get min max l i) input pos in pos `U32.add` U32.uint_to_t l `U32.add` i #pop-options let gaccessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (gaccessor (parse_bounded_vlbytes min max) (parse_u8) (clens_vlbytes_get min max i)) = gaccessor_vlbytes'_get min max (log256' max) i inline_for_extraction let accessor_vlbytes_get (min: nat) // must be a constant (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (i: U32.t) : Tot (accessor (gaccessor_vlbytes_get min max i)) = accessor_vlbytes'_get min max (log256' max) i #push-options "--z3rlimit 128 --max_fuel 2 --initial_fuel 2 --max_ifuel 6 --initial_ifuel 6" let valid_bounded_vlbytes'_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = l in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes' min max l) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_facts (parse_bounded_vlbytes' min max l) h input pos; parse_bounded_vlbytes_eq min max l (bytes_of_slice_from h input pos); let sz = l in valid_facts (parse_bounded_integer sz) h input pos; valid_facts (parse_flbytes (U32.v len)) h input (pos `U32.add` U32.uint_to_t sz) #pop-options let valid_bounded_vlbytes_intro (h: HS.mem) (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : Lemma (requires ( let sz = log256' max in min <= U32.v len /\ U32.v len <= max /\ valid (parse_bounded_integer sz) h input pos /\ contents (parse_bounded_integer sz) h input pos == len /\ U32.v pos + sz <= 4294967295 /\ ( let pos_payload = pos `U32.add` U32.uint_to_t sz in valid (parse_flbytes (U32.v len)) h input pos_payload ))) (ensures ( let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in valid_content_pos (parse_bounded_vlbytes min max) h input pos (contents (parse_flbytes (U32.v len)) h input pos_payload) (pos_payload `U32.add` len) )) = valid_bounded_vlbytes'_intro h min max (log256' max) input pos len inline_for_extraction let finalize_bounded_vlbytes' (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (l: nat { l >= log256' max /\ l <= 4 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = l in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = l in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos_payload + U32.v len == U32.v pos' /\ U32.v pos' <= U32.v input.len /\ valid (parse_bounded_vlbytes' min max l) h' input pos /\ get_valid_pos (parse_bounded_vlbytes' min max l) h' input pos == pos' /\ contents (parse_bounded_vlbytes' min max l) h' input pos == BY.hide (bytes_of_slice_from_to h input pos_payload pos') )) = let h0 = HST.get () in [@inline_let] let sz = l in let pos_payload = write_bounded_integer sz len input pos in let h = HST.get () in [@inline_let] let _ = valid_flbytes_intro h0 (U32.v len) input pos_payload; valid_bounded_vlbytes'_intro h min max l input pos len in pos_payload `U32.add` len inline_for_extraction let finalize_bounded_vlbytes (min: nat) (max: nat { min <= max /\ max > 0 /\ max < 4294967296 } ) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) (len: U32.t) : HST.Stack U32.t (requires (fun h -> let sz = log256' max in live_slice h input /\ min <= U32.v len /\ U32.v len <= max /\ U32.v pos + sz + U32.v len <= U32.v input.len /\ writable input.base (U32.v pos) (U32.v pos + sz) h )) (ensures (fun h pos' h' -> let sz = log256' max in let pos_payload = pos `U32.add` U32.uint_to_t sz in B.modifies (loc_slice_from_to input pos pos_payload) h h' /\ U32.v pos' == U32.v pos_payload + U32.v len /\ valid_content_pos (parse_bounded_vlbytes min max) h' input pos (BY.hide (bytes_of_slice_from_to h input pos_payload pos')) pos' )) = finalize_bounded_vlbytes' min max (log256' max) input pos len inline_for_extraction let validate_bounded_vlgenbytes (vmin: der_length_t) (min: U32.t { U32.v min == vmin } ) (vmax: der_length_t { vmax > 0 }) (max: U32.t { U32.v max == vmax /\ U32.v min <= U32.v max } ) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: validator pk) (rk: leaf_reader pk) : Tot (validator (parse_bounded_vlgenbytes vmin vmax pk)) = validate_synth (validate_bounded_vlgen vmin min vmax max vk rk serialize_all_bytes (validate_all_bytes ()) ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let jump_bounded_vlgenbytes (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (vk: jumper pk) (rk: leaf_reader pk) : Tot (jumper (parse_bounded_vlgenbytes vmin vmax pk)) = jump_synth (jump_bounded_vlgen vmin vmax vk rk serialize_all_bytes ) (fun x -> (x <: parse_bounded_vlbytes_t vmin vmax)) () inline_for_extraction let bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t { vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296 }) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ ( let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ ( let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x
false
false
LowParse.Low.Bytes.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 bounded_vlgenbytes_payload_length (vmin: der_length_t) (vmax: der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296}) (#kk: parser_kind) (#pk: parser kk (bounded_int32 (vmin) (vmax))) (rk: leaf_reader pk) (#rrel #rel: _) (input: slice rrel rel) (pos: U32.t) : HST.Stack U32.t (requires (fun h -> valid (parse_bounded_vlgenbytes vmin vmax pk) h input pos)) (ensures (fun h len h' -> B.modifies B.loc_none h h' /\ valid pk h input pos /\ (let pos1 = get_valid_pos pk h input pos in U32.v pos1 + U32.v len <= U32.v input.len /\ (let x = contents (parse_bounded_vlgenbytes vmin vmax pk) h input pos in let pos' = get_valid_pos (parse_bounded_vlgenbytes vmin vmax pk) h input pos in BY.len x == len /\ valid_content_pos (parse_flbytes (U32.v len)) h input pos1 x pos' /\ bytes_of_slice_from_to h input pos1 pos' == BY.reveal x))))
[]
LowParse.Low.Bytes.bounded_vlgenbytes_payload_length
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
vmin: LowParse.Spec.DER.der_length_t -> vmax: LowParse.Spec.DER.der_length_t{vmax > 0 /\ vmin <= vmax /\ vmax < 4294967296} -> rk: LowParse.Low.Base.leaf_reader pk -> input: LowParse.Slice.slice rrel rel -> pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack FStar.UInt32.t
{ "end_col": 5, "end_line": 1061, "start_col": 1, "start_line": 1037 }
FStar.HyperStack.ST.Stack
val store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to)))
[ { "abbrev": true, "full_module": "LowStar.Buffer // for local variables in store_bytes", "short_module": "BF" }, { "abbrev": true, "full_module": "FStar.UInt64", "short_module": "U64" }, { "abbrev": true, "full_module": "FStar.Int.Cast", "short_module": "Cast" }, { "abbrev": true, "full_module": "FStar.UInt8", "short_module": "U8" }, { "abbrev": true, "full_module": "FStar.HyperStack.ST", "short_module": "HST" }, { "abbrev": true, "full_module": "LowParse.Bytes32", "short_module": "BY" }, { "abbrev": true, "full_module": "LowStar.Buffer", "short_module": "BF" }, { "abbrev": true, "full_module": "LowStar.Monotonic.Buffer", "short_module": "B" }, { "abbrev": true, "full_module": "FStar.HyperStack", "short_module": "HS" }, { "abbrev": true, "full_module": "FStar.UInt32", "short_module": "U32" }, { "abbrev": false, "full_module": "LowParse.Low.Int", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLGen", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.VLData", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Low.Combinators", "short_module": null }, { "abbrev": false, "full_module": "LowParse.Spec.Bytes", "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 store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to) )) = let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ ( let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i) `Seq.equal` Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i) /\ (stop == true ==> i == len) )) (fun _ -> let i = B.index bi 0ul in if i = len then true else begin let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len end ) ; HST.pop_frame ()
val store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to))) let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to))) =
true
null
false
let h0 = HST.get () in HST.push_frame (); let h1 = HST.get () in let bi = BF.alloca 0ul 1ul in let h2 = HST.get () in let len = src_to `U32.sub` src_from in C.Loops.do_while (fun h stop -> B.modifies (B.loc_union (B.loc_region_only true (HS.get_tip h1)) (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` len))) h2 h /\ B.live h bi /\ (let i = Seq.index (B.as_seq h bi) 0 in U32.v i <= U32.v len /\ writable dst (U32.v dst_pos) (U32.v dst_pos + U32.v len) h /\ (Seq.slice (B.as_seq h dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i)) `Seq.equal` (Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_from + U32.v i)) /\ (stop == true ==> i == len))) (fun _ -> let i = B.index bi 0ul in if i = len then true else let x = BY.get src (src_from `U32.add` i) in mbuffer_upd dst (Ghost.hide (U32.v dst_pos)) (Ghost.hide (U32.v dst_pos + U32.v len)) (dst_pos `U32.add` i) x; let i' = i `U32.add` 1ul in B.upd bi 0ul i'; let h' = HST.get () in Seq.lemma_split (Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + U32.v i')) (U32.v i); i' = len); HST.pop_frame ()
{ "checked_file": "LowParse.Low.Bytes.fst.checked", "dependencies": [ "prims.fst.checked", "LowStar.Monotonic.Buffer.fsti.checked", "LowStar.Buffer.fst.checked", "LowParse.Spec.Bytes.fst.checked", "LowParse.Low.VLGen.fst.checked", "LowParse.Low.VLData.fst.checked", "LowParse.Low.Int.fsti.checked", "LowParse.Low.Combinators.fsti.checked", "LowParse.Bytes32.fst.checked", "FStar.UInt8.fsti.checked", "FStar.UInt64.fsti.checked", "FStar.UInt32.fsti.checked", "FStar.Seq.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.Int.Cast.fst.checked", "FStar.HyperStack.ST.fsti.checked", "FStar.HyperStack.fst.checked", "FStar.Ghost.fsti.checked", "FStar.Classical.fsti.checked", "C.Loops.fst.checked" ], "interface_file": false, "source_file": "LowParse.Low.Bytes.fst" }
[]
[ "FStar.Bytes.bytes", "FStar.UInt32.t", "LowStar.Monotonic.Buffer.srel", "LowParse.Bytes.byte", "LowStar.Monotonic.Buffer.mbuffer", "FStar.HyperStack.ST.pop_frame", "Prims.unit", "C.Loops.do_while", "FStar.Monotonic.HyperStack.mem", "Prims.bool", "Prims.l_and", "LowStar.Monotonic.Buffer.modifies", "LowStar.Monotonic.Buffer.loc_union", "LowStar.Monotonic.Buffer.loc_region_only", "FStar.Monotonic.HyperStack.get_tip", "LowStar.Monotonic.Buffer.loc_buffer_from_to", "FStar.UInt32.add", "LowStar.Monotonic.Buffer.live", "LowStar.Buffer.trivial_preorder", "Prims.b2t", "Prims.op_LessThanOrEqual", "FStar.UInt32.v", "LowParse.Low.Base.writable", "Prims.op_Addition", "FStar.Seq.Base.equal", "FStar.Seq.Base.slice", "LowStar.Monotonic.Buffer.as_seq", "FStar.Bytes.byte", "FStar.Bytes.reveal", "Prims.l_imp", "Prims.eq2", "FStar.Seq.Base.index", "Prims.op_Equality", "FStar.Seq.Properties.lemma_split", "FStar.HyperStack.ST.get", "LowStar.Monotonic.Buffer.upd", "FStar.UInt32.__uint_to_t", "LowParse.Low.Base.mbuffer_upd", "FStar.Ghost.hide", "Prims.nat", "FStar.UInt8.t", "FStar.Bytes.get", "LowStar.Monotonic.Buffer.index", "FStar.UInt32.sub", "LowStar.Monotonic.Buffer.length", "FStar.UInt32.uint_to_t", "Prims.op_Negation", "LowStar.Monotonic.Buffer.g_is_null", "LowStar.Buffer.alloca", "FStar.HyperStack.ST.push_frame", "FStar.Bytes.length", "Prims.op_Subtraction", "FStar.Seq.Base.seq" ]
[]
module LowParse.Low.Bytes include LowParse.Spec.Bytes include LowParse.Low.Combinators include LowParse.Low.VLData include LowParse.Low.VLGen include LowParse.Low.Int module U32 = FStar.UInt32 module HS = FStar.HyperStack module B = LowStar.Monotonic.Buffer module BF = LowStar.Buffer // for local variables in store_bytes module BY = LowParse.Bytes32 module HST = FStar.HyperStack.ST module U8 = FStar.UInt8 module Cast = FStar.Int.Cast module U64 = FStar.UInt64 inline_for_extraction let validate_flbytes (sz: nat) (sz64: U64.t { U64.v sz64 == sz /\ sz < 4294967296 } ) : Tot (validator (parse_flbytes sz)) = validate_total_constant_size (parse_flbytes sz) sz64 () inline_for_extraction let jump_flbytes (sz: nat) (sz32: U32.t { U32.v sz32 == sz } ) : Tot (jumper (parse_flbytes sz)) = jump_constant_size (parse_flbytes sz) sz32 () let valid_flbytes_intro (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (U32.v pos + sz <= U32.v s.len /\ live_slice h s)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_facts (parse_flbytes sz) h s pos let valid_pos_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos pos' : U32.t) : Lemma (requires (valid_pos (parse_flbytes sz) h s pos pos')) (ensures (U32.v pos + sz == U32.v pos')) [SMTPat (valid_pos (parse_flbytes sz) h s pos pos')] = valid_facts (parse_flbytes sz) h s pos let valid_flbytes_elim (h: HS.mem) (sz: nat { sz < 4294967296 } ) (#rrel #rel: _) (s: slice rrel rel) (pos: U32.t) : Lemma (requires (valid (parse_flbytes sz) h s pos)) (ensures ( valid_content_pos (parse_flbytes sz) h s pos (BY.hide (bytes_of_slice_from_to h s pos (pos `U32.add` U32.uint_to_t sz))) (pos `U32.add` U32.uint_to_t sz) )) = valid_flbytes_intro h sz s pos let clens_flbytes_slice (sz: nat) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (clens (BY.lbytes sz) (BY.lbytes (U32.v to - U32.v from))) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.slice x from to <: BY.lbytes (U32.v to - U32.v from))); } #push-options "--z3rlimit 16" let gaccessor_flbytes_slice' (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = fun (input: bytes) -> ( begin if Seq.length input < sz then (0) // dummy else (U32.v from) end) let gaccessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) x ==> sz <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_flbytes (U32.v to - U32.v from)) (clens_flbytes_slice sz from to) (gaccessor_flbytes_slice' sz from to); gaccessor_flbytes_slice' sz from to inline_for_extraction let accessor_flbytes_slice (sz: nat { sz < 4294967296 } ) (from: U32.t) (to: U32.t {U32.v from <= U32.v to /\ U32.v to <= sz } ) : Tot (accessor (gaccessor_flbytes_slice sz from to)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_slice sz from to) input pos in pos `U32.add` from #pop-options let clens_flbytes_get (sz: nat) (i: U32.t { U32.v i < sz } ) : Tot (clens (BY.lbytes sz) byte) = { clens_cond = (fun _ -> True); clens_get = (fun (x: BY.lbytes sz) -> (BY.get x i <: byte)); } #push-options "--z3rlimit 16 --max_fuel 1" let gaccessor_flbytes_get' (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor' (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = fun (input: bytes) -> ( begin let res = if Seq.length input < U32.v i then (0) // dummy else (U32.v i) in let g () : Lemma (requires (gaccessor_pre (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input)) (ensures (gaccessor_post (parse_flbytes sz) parse_u8 (clens_flbytes_get sz i) input res)) = parser_kind_prop_equiv (get_parser_kind parse_u8) parse_u8; assert (res == (U32.v i)); parse_u8_spec' (Seq.slice input (U32.v i) (U32.v i + 1)); parse_strong_prefix parse_u8 (Seq.slice input (U32.v i) (U32.v i + 1)) (Seq.slice input (U32.v i) (Seq.length input)) in Classical.move_requires g (); res end) #pop-options let gaccessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (gaccessor (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i)) = assert (forall x . gaccessor_pre (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) x ==> U32.v i <= Seq.length x); gaccessor_prop_equiv (parse_flbytes sz) (parse_u8) (clens_flbytes_get sz i) (gaccessor_flbytes_get' sz i); gaccessor_flbytes_get' sz i inline_for_extraction let accessor_flbytes_get (sz: nat { sz < 4294967296 } ) (i: U32.t { U32.v i < sz } ) : Tot (accessor (gaccessor_flbytes_get sz i)) = fun #rrel #rel input pos -> let h = HST.get () in [@inline_let] let _ = slice_access_eq h (gaccessor_flbytes_get sz i) input pos in pos `U32.add` i (* Temporary: flbytes as leaf values *) (* TODO: convert store_bytes to monotonic buffers, using the "writable" predicate *) #push-options "--z3rlimit 32" inline_for_extraction let store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h )) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to)
false
false
LowParse.Low.Bytes.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": 32, "z3rlimit_factor": 1, "z3seed": 0, "z3smtopt": [], "z3version": "4.8.5" }
null
val store_bytes (src: BY.bytes) (src_from src_to: U32.t) (#rrel #rel: _) (dst: B.mbuffer byte rrel rel) (dst_pos: U32.t) : HST.Stack unit (requires (fun h -> B.live h dst /\ U32.v src_from <= U32.v src_to /\ U32.v src_to <= BY.length src /\ U32.v dst_pos + (U32.v src_to - U32.v src_from) <= B.length dst /\ writable dst (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) h)) (ensures (fun h _ h' -> B.modifies (B.loc_buffer_from_to dst dst_pos (dst_pos `U32.add` (src_to `U32.sub` src_from))) h h' /\ Seq.slice (B.as_seq h' dst) (U32.v dst_pos) (U32.v dst_pos + (U32.v src_to - U32.v src_from)) == Seq.slice (BY.reveal src) (U32.v src_from) (U32.v src_to)))
[]
LowParse.Low.Bytes.store_bytes
{ "file_name": "src/lowparse/LowParse.Low.Bytes.fst", "git_rev": "446a08ce38df905547cf20f28c43776b22b8087a", "git_url": "https://github.com/project-everest/everparse.git", "project_name": "everparse" }
src: FStar.Bytes.bytes -> src_from: FStar.UInt32.t -> src_to: FStar.UInt32.t -> dst: LowStar.Monotonic.Buffer.mbuffer LowParse.Bytes.byte rrel rel -> dst_pos: FStar.UInt32.t -> FStar.HyperStack.ST.Stack Prims.unit
{ "end_col": 18, "end_line": 223, "start_col": 1, "start_line": 192 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_st = c:comp {not (C_Tot? c) }
let comp_st =
false
null
false
c: comp{not (C_Tot? c)}
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Prims.op_Negation", "Pulse.Syntax.Base.uu___is_C_Tot" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames
false
true
Pulse.Syntax.Base.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 comp_st : Type0
[]
Pulse.Syntax.Base.comp_st
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 38, "end_line": 131, "start_col": 14, "start_line": 131 }
Prims.Tot
val tm_fstar (t: host_term) (r: range) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r }
val tm_fstar (t: host_term) (r: range) : term let tm_fstar (t: host_term) (r: range) : term =
false
null
false
{ t = Tm_FStar t; range = r }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.host_term", "Pulse.Syntax.Base.range", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_FStar", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; }
false
true
Pulse.Syntax.Base.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 tm_fstar (t: host_term) (r: range) : term
[]
Pulse.Syntax.Base.tm_fstar
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.host_term -> r: Pulse.Syntax.Base.range -> Pulse.Syntax.Base.term
{ "end_col": 71, "end_line": 103, "start_col": 48, "start_line": 103 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let range_singleton_trigger (r:FStar.Range.range) = True
let range_singleton_trigger (r: FStar.Range.range) =
false
null
false
True
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Range.range", "Prims.l_True", "Prims.logical" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe
false
true
Pulse.Syntax.Base.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 range_singleton_trigger : r: FStar.Range.range -> Prims.logical
[]
Pulse.Syntax.Base.range_singleton_trigger
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: FStar.Range.range -> Prims.logical
{ "end_col": 56, "end_line": 19, "start_col": 52, "start_line": 19 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let var = nat
let var =
false
null
false
nat
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Prims.nat" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst
false
true
Pulse.Syntax.Base.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 var : Type0
[]
Pulse.Syntax.Base.var
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 13, "end_line": 13, "start_col": 10, "start_line": 13 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let host_term = t:R.term { not_tv_unknown t }
let host_term =
false
null
false
t: R.term{not_tv_unknown t}
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Reflection.Types.term", "Pulse.Syntax.Base.not_tv_unknown" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 }
false
true
Pulse.Syntax.Base.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 host_term : Type0
[]
Pulse.Syntax.Base.host_term
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 45, "end_line": 71, "start_col": 16, "start_line": 71 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let range = r:FStar.Range.range { range_singleton_trigger r }
let range =
false
null
false
r: FStar.Range.range{range_singleton_trigger r}
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Range.range", "Pulse.Syntax.Base.range_singleton_trigger" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *)
false
true
Pulse.Syntax.Base.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 range : Type0
[]
Pulse.Syntax.Base.range
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 61, "end_line": 20, "start_col": 12, "start_line": 20 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let term_range (t:term) = t.range
let term_range (t: term) =
false
null
false
t.range
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.__proj__Mkterm__item__range", "Pulse.Syntax.Base.range" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; }
false
true
Pulse.Syntax.Base.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 term_range : t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.range
[]
Pulse.Syntax.Base.term_range
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.range
{ "end_col": 33, "end_line": 102, "start_col": 26, "start_line": 102 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None
let effect_hint =
false
null
false
FStar.Sealed.Inhabited.sealed #(option ctag) None
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Sealed.Inhabited.sealed", "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.ctag", "FStar.Pervasives.Native.None" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost
false
true
Pulse.Syntax.Base.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 effect_hint : Type0
[]
Pulse.Syntax.Base.effect_hint
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 67, "end_line": 145, "start_col": 18, "start_line": 145 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let with_range (t:term') (r:range) = { t; range=r }
let with_range (t: term') (r: range) =
false
null
false
{ t = t; range = r }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.term'", "Pulse.Syntax.Base.range", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range
false
true
Pulse.Syntax.Base.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 with_range : t: Pulse.Syntax.Base.term' -> r: Pulse.Syntax.Base.range -> Pulse.Syntax.Base.term
[]
Pulse.Syntax.Base.with_range
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term' -> r: Pulse.Syntax.Base.range -> Pulse.Syntax.Base.term
{ "end_col": 49, "end_line": 104, "start_col": 39, "start_line": 104 }
Prims.Tot
val tm_pure (p: term) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range }
val tm_pure (p: term) : term let tm_pure (p: term) : term =
false
null
false
{ t = Tm_Pure p; range = p.range }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_Pure", "Pulse.Syntax.Base.__proj__Mkterm__item__range" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0
false
true
Pulse.Syntax.Base.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 tm_pure (p: term) : term
[]
Pulse.Syntax.Base.tm_pure
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
p: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.term
{ "end_col": 62, "end_line": 110, "start_col": 32, "start_line": 110 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let index = nat
let index =
false
null
false
nat
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Prims.nat" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst
false
true
Pulse.Syntax.Base.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 index : Type0
[]
Pulse.Syntax.Base.index
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 15, "end_line": 14, "start_col": 12, "start_line": 14 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let nvar = ppname & var
let nvar =
false
null
false
ppname & var
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Pervasives.Native.tuple2", "Pulse.Syntax.Base.ppname", "Pulse.Syntax.Base.var" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s let comp_u (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u let comp_pre (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.pre let comp_post (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.post let comp_inames (c:comp { C_STAtomic? c \/ C_STGhost? c }) : term = match c with | C_STAtomic inames _ | C_STGhost inames _ -> inames
false
true
Pulse.Syntax.Base.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 nvar : Type0
[]
Pulse.Syntax.Base.nvar
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Type0
{ "end_col": 23, "end_line": 368, "start_col": 11, "start_line": 368 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown
let not_tv_unknown (t: R.term) =
false
null
false
R.inspect_ln t =!= R.Tv_Unknown
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Reflection.Types.term", "Prims.l_not", "Prims.eq2", "FStar.Reflection.V2.Data.term_view", "FStar.Reflection.V2.Builtins.inspect_ln", "FStar.Reflection.V2.Data.Tv_Unknown", "Prims.logical" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 }
false
true
Pulse.Syntax.Base.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 not_tv_unknown : t: FStar.Reflection.Types.term -> Prims.logical
[]
Pulse.Syntax.Base.not_tv_unknown
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: FStar.Reflection.Types.term -> Prims.logical
{ "end_col": 63, "end_line": 70, "start_col": 32, "start_line": 70 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let as_binder (t:term) = { binder_ty=t; binder_ppname=ppname_default}
let as_binder (t: term) =
false
null
false
{ binder_ty = t; binder_ppname = ppname_default }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.Mkbinder", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Base.binder" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s let comp_u (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.u let comp_pre (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.pre let comp_post (c:comp { stateful_comp c }) = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.post let comp_inames (c:comp { C_STAtomic? c \/ C_STGhost? c }) : term = match c with | C_STAtomic inames _ | C_STGhost inames _ -> inames let nvar = ppname & var
false
true
Pulse.Syntax.Base.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 as_binder : t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder
[]
Pulse.Syntax.Base.as_binder
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder
{ "end_col": 68, "end_line": 370, "start_col": 27, "start_line": 370 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c
let stateful_comp (c: comp) =
false
null
false
C_ST? c || C_STAtomic? c || C_STGhost? c
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.op_BarBar", "Pulse.Syntax.Base.uu___is_C_ST", "Pulse.Syntax.Base.uu___is_C_STAtomic", "Pulse.Syntax.Base.uu___is_C_STGhost", "Prims.bool" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res
false
true
Pulse.Syntax.Base.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 stateful_comp : c: Pulse.Syntax.Base.comp -> Prims.bool
[]
Pulse.Syntax.Base.stateful_comp
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp -> Prims.bool
{ "end_col": 42, "end_line": 331, "start_col": 2, "start_line": 331 }
Prims.Tot
val null_binder (t: term) : binder
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default}
val null_binder (t: term) : binder let null_binder (t: term) : binder =
false
null
false
{ binder_ty = t; binder_ppname = ppname_default }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.Mkbinder", "Pulse.Syntax.Base.ppname_default", "Pulse.Syntax.Base.binder" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; }
false
true
Pulse.Syntax.Base.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 null_binder (t: term) : binder
[]
Pulse.Syntax.Base.null_binder
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder
{ "end_col": 43, "end_line": 297, "start_col": 3, "start_line": 297 }
Prims.Tot
val mk_binder (s: string) (r: range) (t: term) : binder
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_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_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r }
val mk_binder (s: string) (r: range) (t: term) : binder let mk_binder (s: string) (r: range) (t: term) : binder =
false
null
false
{ binder_ty = t; binder_ppname = mk_ppname (RT.seal_pp_name s) r }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Prims.string", "Pulse.Syntax.Base.range", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.Mkbinder", "Pulse.Syntax.Base.mk_ppname", "FStar.Reflection.Typing.seal_pp_name", "Pulse.Syntax.Base.binder" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default}
false
true
Pulse.Syntax.Base.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 mk_binder (s: string) (r: range) (t: term) : binder
[]
Pulse.Syntax.Base.mk_binder
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
s: Prims.string -> r: Pulse.Syntax.Base.range -> t: Pulse.Syntax.Base.term -> Pulse.Syntax.Base.binder
{ "end_col": 60, "end_line": 300, "start_col": 3, "start_line": 300 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0
let tm_emp_inames =
false
null
false
with_range Tm_EmpInames FStar.Range.range_0
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_EmpInames", "FStar.Range.range_0" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0
false
true
Pulse.Syntax.Base.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 tm_emp_inames : Pulse.Syntax.Base.term
[]
Pulse.Syntax.Base.tm_emp_inames
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.term
{ "end_col": 63, "end_line": 108, "start_col": 20, "start_line": 108 }
FStar.Pervasives.Lemma
val range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)]
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0
val range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] let range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] =
false
null
true
FStar.Sealed.sealed_singl r FStar.Range.range_0
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "lemma" ]
[ "FStar.Range.range", "FStar.Sealed.sealed_singl", "FStar.Range.__range", "FStar.Range.range_0", "Prims.unit", "Prims.l_True", "Prims.squash", "Prims.eq2", "Prims.Cons", "FStar.Pervasives.pattern", "FStar.Pervasives.smt_pat", "Prims.logical", "Pulse.Syntax.Base.range_singleton_trigger", "Prims.Nil" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0)
false
false
Pulse.Syntax.Base.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 range_singleton (r: FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)]
[]
Pulse.Syntax.Base.range_singleton
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
r: FStar.Range.range -> FStar.Pervasives.Lemma (ensures r == FStar.Range.range_0) [SMTPat (Pulse.Syntax.Base.range_singleton_trigger r)]
{ "end_col": 51, "end_line": 25, "start_col": 4, "start_line": 25 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 }
let ppname_default =
false
null
false
{ name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.Mkppname", "FStar.Sealed.seal", "Prims.string", "FStar.Range.range_0" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range }
false
true
Pulse.Syntax.Base.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 ppname_default : Pulse.Syntax.Base.ppname
[]
Pulse.Syntax.Base.ppname_default
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.ppname
{ "end_col": 31, "end_line": 35, "start_col": 4, "start_line": 34 }
Prims.Tot
val mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_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_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range }
val mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname let mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname =
false
null
false
{ name = name; range = range }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Reflection.Typing.pp_name_t", "FStar.Range.range", "Pulse.Syntax.Base.Mkppname", "Pulse.Syntax.Base.ppname" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 }
false
true
Pulse.Syntax.Base.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 mk_ppname (name: RT.pp_name_t) (range: FStar.Range.range) : ppname
[]
Pulse.Syntax.Base.mk_ppname
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
name: FStar.Reflection.Typing.pp_name_t -> range: FStar.Range.range -> Pulse.Syntax.Base.ppname
{ "end_col": 17, "end_line": 40, "start_col": 4, "start_line": 39 }
Prims.Tot
val mk_ppname_no_range (s: string) : ppname
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_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_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; }
val mk_ppname_no_range (s: string) : ppname let mk_ppname_no_range (s: string) : ppname =
false
null
false
{ name = FStar.Sealed.seal s; range = FStar.Range.range_0 }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Prims.string", "Pulse.Syntax.Base.Mkppname", "FStar.Sealed.seal", "FStar.Range.range_0", "Pulse.Syntax.Base.ppname" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range }
false
true
Pulse.Syntax.Base.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 mk_ppname_no_range (s: string) : ppname
[]
Pulse.Syntax.Base.mk_ppname_no_range
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
s: Prims.string -> Pulse.Syntax.Base.ppname
{ "end_col": 30, "end_line": 45, "start_col": 2, "start_line": 44 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 }
let as_fv l =
false
null
false
{ fv_name = l; fv_range = FStar.Range.range_0 }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Reflection.Types.name", "Pulse.Syntax.Base.Mkfv", "FStar.Range.range_0", "Pulse.Syntax.Base.fv" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range;
false
true
Pulse.Syntax.Base.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 as_fv : l: FStar.Reflection.Types.name -> Pulse.Syntax.Base.fv
[]
Pulse.Syntax.Base.as_fv
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
l: FStar.Reflection.Types.name -> Pulse.Syntax.Base.fv
{ "end_col": 59, "end_line": 68, "start_col": 16, "start_line": 68 }
Prims.Tot
val tm_forall_sl (u: universe) (b: binder) (body: vprop) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range }
val tm_forall_sl (u: universe) (b: binder) (body: vprop) : term let tm_forall_sl (u: universe) (b: binder) (body: vprop) : term =
false
null
false
{ t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.universe", "Pulse.Syntax.Base.binder", "Pulse.Syntax.Base.vprop", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_ForallSL", "Pulse.RuntimeUtils.union_ranges", "Pulse.Syntax.Base.__proj__Mkterm__item__range", "Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range }
false
true
Pulse.Syntax.Base.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 tm_forall_sl (u: universe) (b: binder) (body: vprop) : term
[]
Pulse.Syntax.Base.tm_forall_sl
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
u52: Pulse.Syntax.Base.universe -> b: Pulse.Syntax.Base.binder -> body: Pulse.Syntax.Base.vprop -> Pulse.Syntax.Base.term
{ "end_col": 143, "end_line": 113, "start_col": 65, "start_line": 113 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_vprop = with_range Tm_VProp FStar.Range.range_0
let tm_vprop =
false
null
false
with_range Tm_VProp FStar.Range.range_0
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_VProp", "FStar.Range.range_0" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r }
false
true
Pulse.Syntax.Base.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 tm_vprop : Pulse.Syntax.Base.term
[]
Pulse.Syntax.Base.tm_vprop
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.term
{ "end_col": 54, "end_line": 105, "start_col": 15, "start_line": 105 }
Prims.Tot
val tm_star (l r: vprop) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range }
val tm_star (l r: vprop) : term let tm_star (l r: vprop) : term =
false
null
false
{ t = Tm_Star l r; range = RU.union_ranges l.range r.range }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.vprop", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_Star", "Pulse.RuntimeUtils.union_ranges", "Pulse.Syntax.Base.__proj__Mkterm__item__range", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0
false
true
Pulse.Syntax.Base.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 tm_star (l r: vprop) : term
[]
Pulse.Syntax.Base.tm_star
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
l: Pulse.Syntax.Base.vprop -> r: Pulse.Syntax.Base.vprop -> Pulse.Syntax.Base.term
{ "end_col": 99, "end_line": 111, "start_col": 43, "start_line": 111 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_unknown = with_range Tm_Unknown FStar.Range.range_0
let tm_unknown =
false
null
false
with_range Tm_Unknown FStar.Range.range_0
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_Unknown", "FStar.Range.range_0" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0
false
true
Pulse.Syntax.Base.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 tm_unknown : Pulse.Syntax.Base.term
[]
Pulse.Syntax.Base.tm_unknown
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.term
{ "end_col": 58, "end_line": 109, "start_col": 17, "start_line": 109 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_emp = with_range Tm_Emp FStar.Range.range_0
let tm_emp =
false
null
false
with_range Tm_Emp FStar.Range.range_0
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_Emp", "FStar.Range.range_0" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0
false
true
Pulse.Syntax.Base.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 tm_emp : Pulse.Syntax.Base.term
[]
Pulse.Syntax.Base.tm_emp
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.term
{ "end_col": 50, "end_line": 107, "start_col": 13, "start_line": 107 }
Prims.Tot
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_inames = with_range Tm_Inames FStar.Range.range_0
let tm_inames =
false
null
false
with_range Tm_Inames FStar.Range.range_0
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.with_range", "Pulse.Syntax.Base.Tm_Inames", "FStar.Range.range_0" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r }
false
true
Pulse.Syntax.Base.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 tm_inames : Pulse.Syntax.Base.term
[]
Pulse.Syntax.Base.tm_inames
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.term
{ "end_col": 56, "end_line": 106, "start_col": 16, "start_line": 106 }
Prims.Tot
val ctag_of_comp_st (c: comp_st) : ctag
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost
val ctag_of_comp_st (c: comp_st) : ctag let ctag_of_comp_st (c: comp_st) : ctag =
false
null
false
match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp_st", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.STT", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.STT_Atomic", "Pulse.Syntax.Base.STT_Ghost", "Pulse.Syntax.Base.ctag" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c)
false
true
Pulse.Syntax.Base.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 ctag_of_comp_st (c: comp_st) : ctag
[]
Pulse.Syntax.Base.ctag_of_comp_st
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp_st -> Pulse.Syntax.Base.ctag
{ "end_col": 30, "end_line": 153, "start_col": 2, "start_line": 150 }
Prims.Tot
val tm_exists_sl (u: universe) (b: binder) (body: vprop) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range }
val tm_exists_sl (u: universe) (b: binder) (body: vprop) : term let tm_exists_sl (u: universe) (b: binder) (body: vprop) : term =
false
null
false
{ t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range }
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.universe", "Pulse.Syntax.Base.binder", "Pulse.Syntax.Base.vprop", "Pulse.Syntax.Base.Mkterm", "Pulse.Syntax.Base.Tm_ExistsSL", "Pulse.RuntimeUtils.union_ranges", "Pulse.Syntax.Base.__proj__Mkterm__item__range", "Pulse.Syntax.Base.__proj__Mkbinder__item__binder_ty", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range }
false
true
Pulse.Syntax.Base.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 tm_exists_sl (u: universe) (b: binder) (body: vprop) : term
[]
Pulse.Syntax.Base.tm_exists_sl
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
u49: Pulse.Syntax.Base.universe -> b: Pulse.Syntax.Base.binder -> body: Pulse.Syntax.Base.vprop -> Pulse.Syntax.Base.term
{ "end_col": 143, "end_line": 112, "start_col": 65, "start_line": 112 }
Prims.Tot
val as_effect_hint (c: ctag) : effect_hint
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c)
val as_effect_hint (c: ctag) : effect_hint let as_effect_hint (c: ctag) : effect_hint =
false
null
false
FStar.Sealed.seal (Some c)
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.ctag", "FStar.Sealed.seal", "FStar.Pervasives.Native.option", "FStar.Pervasives.Native.Some", "Pulse.Syntax.Base.effect_hint" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None
false
true
Pulse.Syntax.Base.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 as_effect_hint (c: ctag) : effect_hint
[]
Pulse.Syntax.Base.as_effect_hint
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.ctag -> Pulse.Syntax.Base.effect_hint
{ "end_col": 70, "end_line": 147, "start_col": 44, "start_line": 147 }
Prims.Tot
val default_effect_hint:effect_hint
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let default_effect_hint : effect_hint = FStar.Sealed.seal None
val default_effect_hint:effect_hint let default_effect_hint:effect_hint =
false
null
false
FStar.Sealed.seal None
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "FStar.Sealed.seal", "FStar.Pervasives.Native.option", "Pulse.Syntax.Base.ctag", "FStar.Pervasives.Native.None" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost
false
true
Pulse.Syntax.Base.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 default_effect_hint:effect_hint
[]
Pulse.Syntax.Base.default_effect_hint
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
Pulse.Syntax.Base.effect_hint
{ "end_col": 62, "end_line": 146, "start_col": 40, "start_line": 146 }
Prims.Tot
val comp_res (c: comp) : term
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res
val comp_res (c: comp) : term let comp_res (c: comp) : term =
false
null
false
match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.__proj__Mkst_comp__item__res" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) }
false
true
Pulse.Syntax.Base.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 comp_res (c: comp) : term
[]
Pulse.Syntax.Base.comp_res
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp -> Pulse.Syntax.Base.term
{ "end_col": 26, "end_line": 328, "start_col": 2, "start_line": 324 }
Prims.Tot
val st_comp_of_comp (c: comp{stateful_comp c}) : st_comp
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s
val st_comp_of_comp (c: comp{stateful_comp c}) : st_comp let st_comp_of_comp (c: comp{stateful_comp c}) : st_comp =
false
null
false
match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Pulse.Syntax.Base.stateful_comp", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.term" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c
false
false
Pulse.Syntax.Base.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 st_comp_of_comp (c: comp{stateful_comp c}) : st_comp
[]
Pulse.Syntax.Base.st_comp_of_comp
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> Pulse.Syntax.Base.st_comp
{ "end_col": 22, "end_line": 337, "start_col": 2, "start_line": 334 }
Prims.Tot
val with_st_comp (c: comp{stateful_comp c}) (s: st_comp) : comp
[ { "abbrev": true, "full_module": "FStar.Tactics.V2", "short_module": "T" }, { "abbrev": false, "full_module": "FStar.List.Tot", "short_module": null }, { "abbrev": true, "full_module": "Pulse.RuntimeUtils", "short_module": "RU" }, { "abbrev": true, "full_module": "FStar.Reflection.V2", "short_module": "R" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing", "short_module": "RT" }, { "abbrev": true, "full_module": "FStar.Reflection.Typing.Builtins", "short_module": "RTB" }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "Pulse.Syntax", "short_module": null }, { "abbrev": false, "full_module": "FStar.Pervasives", "short_module": null }, { "abbrev": false, "full_module": "Prims", "short_module": null }, { "abbrev": false, "full_module": "FStar", "short_module": null } ]
false
let with_st_comp (c:comp{stateful_comp c}) (s:st_comp) : comp = match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s
val with_st_comp (c: comp{stateful_comp c}) (s: st_comp) : comp let with_st_comp (c: comp{stateful_comp c}) (s: st_comp) : comp =
false
null
false
match c with | C_ST _ -> C_ST s | C_STAtomic inames _ -> C_STAtomic inames s | C_STGhost inames _ -> C_STGhost inames s
{ "checked_file": "Pulse.Syntax.Base.fsti.checked", "dependencies": [ "Pulse.RuntimeUtils.fsti.checked", "prims.fst.checked", "FStar.Tactics.V2.fst.checked", "FStar.Sealed.Inhabited.fst.checked", "FStar.Sealed.fsti.checked", "FStar.Reflection.V2.fst.checked", "FStar.Reflection.Typing.Builtins.fsti.checked", "FStar.Reflection.Typing.fsti.checked", "FStar.Range.fsti.checked", "FStar.Pervasives.Native.fst.checked", "FStar.Pervasives.fsti.checked", "FStar.List.Tot.fst.checked" ], "interface_file": false, "source_file": "Pulse.Syntax.Base.fsti" }
[ "total" ]
[ "Pulse.Syntax.Base.comp", "Prims.b2t", "Pulse.Syntax.Base.stateful_comp", "Pulse.Syntax.Base.st_comp", "Pulse.Syntax.Base.C_ST", "Pulse.Syntax.Base.term", "Pulse.Syntax.Base.C_STAtomic", "Pulse.Syntax.Base.C_STGhost" ]
[]
module Pulse.Syntax.Base module RTB = FStar.Reflection.Typing.Builtins module RT = FStar.Reflection.Typing module R = FStar.Reflection.V2 module RU = Pulse.RuntimeUtils open FStar.List.Tot module T = FStar.Tactics.V2 type constant = R.vconst let var = nat let index = nat type universe = R.universe (* locally nameless. *) let range_singleton_trigger (r:FStar.Range.range) = True let range = r:FStar.Range.range { range_singleton_trigger r } let range_singleton (r:FStar.Range.range) : Lemma (ensures r == FStar.Range.range_0) [SMTPat (range_singleton_trigger r)] = FStar.Sealed.sealed_singl r FStar.Range.range_0 noeq type ppname = { name : RT.pp_name_t; range : range } let ppname_default = { name = FStar.Sealed.seal "_"; range = FStar.Range.range_0 } let mk_ppname (name:RT.pp_name_t) (range:FStar.Range.range) : ppname = { name = name; range = range } let mk_ppname_no_range (s:string) : ppname = { name = FStar.Sealed.seal s; range = FStar.Range.range_0; } noeq type bv = { bv_index : index; bv_ppname : ppname; } noeq type nm = { nm_index : var; nm_ppname : ppname; } type qualifier = | Implicit noeq type fv = { fv_name : R.name; fv_range : range; } let as_fv l = { fv_name = l; fv_range = FStar.Range.range_0 } let not_tv_unknown (t:R.term) = R.inspect_ln t =!= R.Tv_Unknown let host_term = t:R.term { not_tv_unknown t } [@@ no_auto_projectors] noeq type term' = | Tm_Emp : term' | Tm_Pure : p:term -> term' | Tm_Star : l:vprop -> r:vprop -> term' | Tm_ExistsSL : u:universe -> b:binder -> body:vprop -> term' | Tm_ForallSL : u:universe -> b:binder -> body:vprop -> term' | Tm_VProp : term' | Tm_Inames : term' // type inames | Tm_EmpInames : term' | Tm_FStar : host_term -> term' | Tm_Unknown : term' and vprop = term and typ = term and binder = { binder_ty : term; binder_ppname : ppname; } and term = { t : term'; range : range; } let term_range (t:term) = t.range let tm_fstar (t:host_term) (r:range) : term = { t = Tm_FStar t; range=r } let with_range (t:term') (r:range) = { t; range=r } let tm_vprop = with_range Tm_VProp FStar.Range.range_0 let tm_inames = with_range Tm_Inames FStar.Range.range_0 let tm_emp = with_range Tm_Emp FStar.Range.range_0 let tm_emp_inames = with_range Tm_EmpInames FStar.Range.range_0 let tm_unknown = with_range Tm_Unknown FStar.Range.range_0 let tm_pure (p:term) : term = { t = Tm_Pure p; range = p.range } let tm_star (l:vprop) (r:vprop) : term = { t = Tm_Star l r; range = RU.union_ranges l.range r.range } let tm_exists_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ExistsSL u b body; range = RU.union_ranges b.binder_ty.range body.range } let tm_forall_sl (u:universe) (b:binder) (body:vprop) : term = { t = Tm_ForallSL u b body; range = RU.union_ranges b.binder_ty.range body.range } noeq type st_comp = { (* ST pre (x:res) post ... x is free in post *) u:universe; res:term; pre:vprop; post:vprop } noeq type comp = | C_Tot : term -> comp | C_ST : st_comp -> comp | C_STAtomic : term -> st_comp -> comp // inames | C_STGhost : term -> st_comp -> comp // inames let comp_st = c:comp {not (C_Tot? c) } noeq type pattern = | Pat_Cons : fv -> list (pattern & bool) -> pattern | Pat_Constant : constant -> pattern | Pat_Var : RT.pp_name_t -> ty:RT.sort_t -> pattern | Pat_Dot_Term : option term -> pattern type ctag = | STT | STT_Atomic | STT_Ghost let effect_hint = FStar.Sealed.Inhabited.sealed #(option ctag) None let default_effect_hint : effect_hint = FStar.Sealed.seal None let as_effect_hint (c:ctag) : effect_hint = FStar.Sealed.seal (Some c) let ctag_of_comp_st (c:comp_st) : ctag = match c with | C_ST _ -> STT | C_STAtomic _ _ -> STT_Atomic | C_STGhost _ _ -> STT_Ghost noeq type proof_hint_type = | ASSERT { p:vprop } | FOLD { names:option (list string); p:vprop; } | UNFOLD { names:option (list string); p:vprop } | RENAME { //rename e as e' [in p] pairs:list (term & term); goal: option term } | REWRITE { t1:vprop; t2:vprop; } (* terms with STT types *) [@@ no_auto_projectors] noeq type st_term' = | Tm_Return { ctag:ctag; insert_eq:bool; term: term; } | Tm_Abs { b:binder; q:option qualifier; ascription: comp; body:st_term; } | Tm_STApp { head:term; arg_qual:option qualifier; arg:term; } | Tm_Bind { binder:binder; head:st_term; body:st_term; } | Tm_TotBind { // tot here means non-stateful, head could also be ghost, we should rename it binder:binder; head:term; body:st_term; } | Tm_If { b:term; then_:st_term; else_:st_term; post:option vprop; } | Tm_Match { sc:term; returns_:option vprop; brs: list branch; } | Tm_IntroPure { p:term; } | Tm_ElimExists { p:vprop; } | Tm_IntroExists { p:vprop; witnesses:list term; } | Tm_While { invariant:term; condition:st_term; condition_var: ppname; body:st_term; } | Tm_Par { pre1:term; body1:st_term; post1:term; pre2:term; body2:st_term; post2:term; } | Tm_WithLocal { binder:binder; initializer:term; body:st_term; } | Tm_WithLocalArray { binder:binder; initializer:term; length:term; body:st_term; } | Tm_Rewrite { t1:term; t2:term; } | Tm_Admit { ctag:ctag; u:universe; typ:term; post:option term; } | Tm_ProofHintWithBinders { hint_type:proof_hint_type; binders:list binder; t:st_term } and st_term = { term : st_term'; range : range; effect_tag: effect_hint } and branch = pattern & st_term noeq type decl' = | FnDecl { (* A function declaration, currently the only Pulse top-level decl. This will be mostly checked as a nested Tm_Abs with bs and body, especially if non-recursive. *) id : R.ident; isrec : bool; bs : list (option qualifier & binder & bv); comp : comp; (* bs in scope *) meas : (meas:option term{Some? meas ==> isrec}); (* bs in scope *) body : st_term; (* bs in scope *) } and decl = { d : decl'; range : range; } let null_binder (t:term) : binder = {binder_ty=t;binder_ppname=ppname_default} let mk_binder (s:string) (r:range) (t:term) : binder = {binder_ty=t;binder_ppname=mk_ppname (RT.seal_pp_name s) r } val eq_univ (u1 u2:universe) : b:bool { b <==> (u1 == u2) } val eq_tm (t1 t2:term) : b:bool { b <==> (t1 == t2) } val eq_st_comp (s1 s2:st_comp) : b:bool { b <==> (s1 == s2) } val eq_comp (c1 c2:comp) : b:bool { b <==> (c1 == c2) } val eq_tm_opt (t1 t2:option term) : b:bool { b <==> (t1 == t2) } val eq_tm_list (t1 t2:list term) : b:bool { b <==> (t1 == t2) } val eq_st_term (t1 t2:st_term) : b:bool { b <==> (t1 == t2) } let comp_res (c:comp) : term = match c with | C_Tot ty -> ty | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s.res let stateful_comp (c:comp) = C_ST? c || C_STAtomic? c || C_STGhost? c let st_comp_of_comp (c:comp{stateful_comp c}) : st_comp = match c with | C_ST s | C_STAtomic _ s | C_STGhost _ s -> s
false
false
Pulse.Syntax.Base.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 with_st_comp (c: comp{stateful_comp c}) (s: st_comp) : comp
[]
Pulse.Syntax.Base.with_st_comp
{ "file_name": "lib/steel/pulse/Pulse.Syntax.Base.fsti", "git_rev": "7fbb54e94dd4f48ff7cb867d3bae6889a635541e", "git_url": "https://github.com/FStarLang/steel.git", "project_name": "steel" }
c: Pulse.Syntax.Base.comp{Pulse.Syntax.Base.stateful_comp c} -> s: Pulse.Syntax.Base.st_comp -> Pulse.Syntax.Base.comp
{ "end_col": 44, "end_line": 343, "start_col": 2, "start_line": 340 }